Skip to content
This repository has been archived by the owner on Jan 16, 2021. It is now read-only.

Commit

Permalink
557
Browse files Browse the repository at this point in the history
  • Loading branch information
akkartik committed Apr 25, 2011
1 parent 83af988 commit 521a299
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions 037collect.wart
@@ -0,0 +1,8 @@
(mac collect body
`(with (,$acc (queue)
,$old-yield (symbol-function 'yield))
(= (symbol-function 'yield) [enq ,$acc _])
(do ,@body)
(= (symbol-function 'yield) ,$old-yield)
(as cons ,$acc)))
(def yield(_) (prn 'yield-outside-collect))
12 changes: 12 additions & 0 deletions 037collect.wtst
@@ -0,0 +1,12 @@
(test "collect works"
:valueof (collect (map0 [yield (* _ 10)] '(1 2 3)))
:should be '(10 20 30))

(wt-eval '(def fooyield(_) (yield (* _ 10))))
(test "collect can yield from deep inside the call hierarchy"
:valueof (collect (map0 #'fooyield '(1 2 3)))
:should be '(10 20 30))

(test "collect/yield can nest"
:valueof (collect (yield (collect yield.1)))
:should be '((1)))

0 comments on commit 521a299

Please sign in to comment.