This repository has been archived by the owner on Jan 16, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
20 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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))) |