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
(defmacro -> (init &rest funcs) | |
(cond | |
((null funcs) `,init) | |
((eql 'if (car funcs)) | |
(let* ((gensym (gensym))) | |
`(-> (let ((,gensym ,init)) | |
(if ,gensym (-> ,gensym ,(cadr funcs)) | |
(-> ,gensym ,(caddr funcs))) | |
,@(cdddr funcs))))) | |
((and (consp (car funcs)) (not (eql 'lambda (caar funcs)))) |
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
(defmacro flip-flop (left right) | |
"Evaluates to false until the left test is satisfied. Then evaluates to true until the right test is satisfied, etc." | |
;; create a collision-safe name for our state variable | |
(let ((state-var (gensym))) | |
;; create a toplevel variable to keep state of flip-flop | |
`(progn | |
(defvar ,state-var nil)) |
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
;; A couple of silly macros for a language that has defmacro but no tail-recursion | |
;; the mutual recursion macro is even worse, because you can only really 'call' one of the functions | |
(defmacro recur (arg-pairs &body body) | |
(let ((arg-names (mapcar #'car arg-pairs)) ;; extract loop variable names | |
(arg-vals (mapcar #'cadr arg-pairs))) ;; extract start values | |
;; block to return from | |
`(block nil |