Created
August 6, 2009 21:09
-
-
Save fffej/163565 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 rec-seq | |
[binding-name & body] | |
`(let [s# (atom nil)] | |
(reset! s# (lazy-seq (let [~binding-name @s#] ~@body))))) | |
(defmacro rec-cat | |
[binding-name & exprs] | |
`(rec-seq ~binding-name (lazy-cat ~@exprs))) | |
;; Fibonacci | |
(take 10 (rec-cat [1 2] (map + s (next s)))) | |
;; Gives (1 2 3 5 8 13 21 34 55 89) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment