diff options
author | Colin Okay <cbeok@protonmail.com> | 2020-08-13 11:11:56 -0500 |
---|---|---|
committer | Colin Okay <cbeok@protonmail.com> | 2020-08-13 11:11:56 -0500 |
commit | c80b5a82030246cfe3b0305874b8a682fad4c199 (patch) | |
tree | f1a710e83767a4c223043416151b29d77ef8d6be | |
parent | e8c0f8e58b0039d8d3ed886654a5452168168436 (diff) |
reader-macros optional. added lazyness stuff
-rw-r--r-- | macros.lisp | 43 | ||||
-rw-r--r-- | package.lisp | 4 |
2 files changed, 36 insertions, 11 deletions
diff --git a/macros.lisp b/macros.lisp index 37d111e..de2dfbf 100644 --- a/macros.lisp +++ b/macros.lisp @@ -91,9 +91,6 @@ those numbers. - - - (defmacro and> (&rest preds) (let ((block-label (gensym))) `(let ((preds (list ,@preds))) @@ -118,10 +115,36 @@ those numbers. (when acc (return-from ,block-label acc))) acc)))))) - -(set-dispatch-macro-character - #\# #\$ - (lambda (stream subchar arg) - (declare (ignore arg subchar)) - (let ((form (read stream))) - (list '$$ form)))) +(defmacro make-lazy (form) + (let ((run-p (gensym)) + (val (gensym))) + `(let ((,run-p nil) + (,val nil)) + (lambda () + (unless ,run-p + (setf ,val ,form) + (setf ,run-p t)) + ,val)))) + + +(defun enable-partial-eval-reader-macro () + (set-dispatch-macro-character + #\# #\$ + (lambda (stream subchar arg) + (declare (ignore arg subchar)) + (list '$$ (read stream))))) + + +(defun enable-lazy-eval-reader-macros () + + (set-dispatch-macro-character + #\# #\~ + (lambda (stream subchar arg) + (declare (ignore arg subchar)) + (list 'make-lazy (read stream)))) + + (set-dispatch-macro-character + #\# #\! + (lambda (stream subchar arg) + (declare (ignore arg subchar)) + (list 'funcall (read stream))))) diff --git a/package.lisp b/package.lisp index 3763ee0..e1c0bbc 100644 --- a/package.lisp +++ b/package.lisp @@ -6,4 +6,6 @@ #:>> #:<> #:and> - #:or>)) + #:or> + #:enable-partial-eval-reader-macro + #:enable-lazy-eval-reader-macros)) |