aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--macros.lisp43
-rw-r--r--package.lisp4
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))