Created
March 5, 2024 19:21
-
-
Save telent/b6616c3e166234cf0261dcd52652913e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(fn sleep [x] (: (io.popen (.. "sleep " (tostring x))) :close)) ;; simulate a slow process | |
(fn tick-producer [] | |
(coroutine.wrap | |
(fn [] | |
(var i 0) | |
(while (< i 10) | |
(set i (+ 1 i)) | |
(coroutine.yield i) | |
(sleep 1) | |
)))) | |
(let [ticks (tick-producer)] | |
(accumulate [finished false | |
t ticks | |
&until finished] | |
(do (print t) | |
(= t 4))) | |
(print "next" (ticks))) |
This file contains hidden or 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
$ fennel foo.fnl | |
1 | |
2 | |
3 | |
4 | |
[... pauses ...] | |
next 6 |
Author
telent
commented
Mar 5, 2024
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment