Created
April 10, 2011 09:54
-
-
Save danlentz/912198 to your computer and use it in GitHub Desktop.
examples of set-macro-character
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(set-macro-character #\⌋ (get-macro-character #\))) | |
(set-macro-character #\⌊ | |
(lambda (stream char) | |
(declare (ignore char)) | |
(prog1 `(floor ,(read stream t nil t)) | |
(let ((char (peek-char t stream t nil t))) | |
(if (char= char #\⌋) | |
(read-char stream t nil t) | |
(error 'reader-error :stream stream)))))) | |
(set-macro-character #\⌉ (get-macro-character #\))) | |
(set-macro-character #\⌈ | |
(lambda (stream char) | |
(declare (ignore char)) | |
(prog1 `(ceiling ,(read stream t nil t)) | |
(let ((char (peek-char t stream t nil t))) | |
(if (char= char #\⌉) | |
(read-char stream t nil t) | |
(error 'reader-error :stream stream)))))) | |
(set-macro-character #\√ | |
(lambda (stream char) | |
(declare (ignore char)) | |
`(sqrt ,(read stream t nil t)))) | |
(set-macro-character #\¬ | |
(lambda (stream char) | |
(declare (ignore char)) | |
`(not ,(read stream t nil t)))) | |
(set-macro-character #\≠ (constantly '/=)) | |
(set-macro-character #\≤ (constantly '<=)) | |
(set-macro-character #\≥ (constantly '>=)) | |
(set-macro-character #\∅ (constantly ())) | |
;;; | |
;;; ∃ n ∈ (1 2 3 4 5): (evenp n) => T | |
(set-macro-character #\∃ | |
(lambda (stream char) | |
(declare (ignore char)) | |
(let ((variable (read stream t nil t)) | |
(element-of (progn (assert (char= #\∈ (peek-char t stream t nil t))) | |
(read-char stream t nil t))) | |
(list (read stream t nil t)) | |
(colon (progn (assert (char= #\: (peek-char t stream t nil t))) | |
(read-char stream t nil t))) | |
(expression (read stream t nil t))) | |
`(some (lambda (,variable) ,expression) ',list)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment