Skip to content

Instantly share code, notes, and snippets.

@fffej
Created August 6, 2009 21:09
Show Gist options
  • Save fffej/163565 to your computer and use it in GitHub Desktop.
Save fffej/163565 to your computer and use it in GitHub Desktop.
(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