Created
June 20, 2010 01:30
-
-
Save trptcolin/445462 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
(defmacro lazy-cons | |
"Expands to code which produces a seq object whose first is | |
first-expr and whose rest is rest-expr, neither of which is | |
evaluated until first/rest is called. Each expr will be evaluated at most | |
once per step in the sequence, e.g. calling first/rest repeatedly on the | |
same node of the seq evaluates first/rest-expr once - the values they yield are | |
cached." | |
[first-expr & rest-expr] | |
(list 'new 'clojure.lang.LazyCons (list `fn (list [] first-expr) (list* [(gensym)] rest-expr)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment