| (mac lcc (name . body)
`(ccc (fn (,name) ,@body)))
(mac defgen (name args . body)
(w/uniq (gen ret)
`(def ,name ,args
(def ,gen ()
(lcc ,ret
(def yield (value)
(lcc next
(= ,gen (fn () (next #f)))
(,ret value)))
,@body))
(fn () (,gen)))))
;; Example
(mac iterate (names-values . body)
`((afn ,names-values ,@body) ,@names-values))
(defgen fib (x0 x1)
(yield x0)
(iterate (x0 x1)
(yield x1)
(self x1 (+ x0 x1))))
(= genfibs (fib 0 1))
(repeat 10
(prn (genfibs)))
|