1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-25 01:37:19 +00:00

Add the fiber-fn macro which slightly generalizes coro.

This commit is contained in:
Calvin Rose 2021-07-22 17:59:01 -05:00
parent 54d73f6722
commit a89c377c92

View File

@ -588,10 +588,15 @@
~(fiber/new (fn [] (loop ,head (yield (do ,;body)))) :yi))
(defmacro coro
"A wrapper for making fibers. Same as (fiber/new (fn [] ;body) :yi)."
"A wrapper for making fibers that may yield multiple values (coroutine). Same as (fiber/new (fn [] ;body) :yi)."
[& body]
(tuple fiber/new (tuple 'fn '[] ;body) :yi))
(defmacro fiber-fn
"A wrapper for making fibers. Same as (fiber/new (fn [] ;body) flags)."
[flags & body]
(tuple fiber/new (tuple 'fn '[] ;body) flags))
(defn sum
"Returns the sum of xs. If xs is empty, returns 0."
[xs]