-
-
Save vendethiel/c46fbc58d881d346c8eb0270eb1d8b3e to your computer and use it in GitHub Desktop.
This file contains 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
(defun print-intermediate (x) | |
(format t"I got intermediate val: ~d~%" x) | |
nil) | |
(defun traverse-rec (body fn) | |
(if (listp body) | |
(or (funcall fn body) (mapcar (lambda (sub) (traverse-rec sub fn)) body)) ;; note: this means fn can't return an explicitly-nil value | |
body)) | |
(defmacro prog<> (body) | |
(let* ((prog1-sym (gensym "prog1")) | |
prog1-target | |
(newbody | |
(traverse-rec body | |
(lambda (sub) | |
(if (and (= (length sub) 2) | |
(equal (car sub) '<>)) | |
(progn | |
(setf prog1-target (cadr sub)) | |
prog1-sym) | |
nil))))) | |
`(let ((,prog1-sym ,prog1-target)) (prog1 ,prog1-sym ,newbody)))) | |
(defvar a (prog<> (print-intermediate (<> 1)))) | |
(princ a) |
This file contains 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
I got intermediate val: 1 | |
1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment