diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f540d36..f3a02576 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. ## Unreleased - ??? +- Add `fiber/last-value` to get the value that was last yielded, errored, or signaled + by a fiber. +- Remove `:generate` verb from `loop` macros. Instead, use the `:in` verb + which will now work on fibers as well as other data structures. - Define `next`, `get`, and `in` for fibers. This lets `each`, `map`, and similar iteration macros can now iterate over fibers. - Remove macro `eachy`, which can be replaced by `each`. diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 496e1264..6688c81a 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -442,17 +442,6 @@ (def ,binding ,i) ,body)))) -(defn- loop-fiber-template - [binding expr body] - (with-syms [f s] - (def ds (if (idempotent? binding) binding (gensym))) - ~(let [,f ,expr] - (while true - (def ,ds (,resume ,f)) - (if (= :dead (,fiber/status ,f)) (break)) - ,;(if (= ds binding) [] [~(def ,binding ,ds)]) - ,;body)))) - (defn- loop1 [body head i] @@ -490,7 +479,6 @@ :pairs (each-template binding object :pairs [rest]) :in (each-template binding object :each [rest]) :iterate (iterate-template binding object rest) - :generate (loop-fiber-template binding object [rest]) (error (string "unexpected loop verb " verb))))) (defmacro forv @@ -564,9 +552,6 @@ * :in -- iterate over the values in a data structure or fiber. - * :generate -- iterate over values yielded from a fiber. Can be paired with - the generator function for the producer/consumer pattern. - `loop` also accepts conditionals to refine the looping further. Conditionals are of the form: @@ -614,7 +599,7 @@ (undef _env) (undef loop1 check-indexed for-template for-var-template iterate-template - each-template range-template loop-fiber-template) + each-template range-template) (defn sum "Returns the sum of xs. If xs is empty, returns 0." diff --git a/test/suite0002.janet b/test/suite0002.janet index 15ce0fa7..e606c5e4 100644 --- a/test/suite0002.janet +++ b/test/suite0002.janet @@ -49,7 +49,7 @@ # Generators (def gen (generate [x :range [0 100] :when (pos? (% x 4))] x)) (var gencount 0) -(loop [x :generate gen] +(loop [x :in gen] (++ gencount) (assert (pos? (% x 4)) "generate in loop")) (assert (= gencount 75) "generate loop count") diff --git a/test/suite0008.janet b/test/suite0008.janet index a10508bf..4eb70040 100644 --- a/test/suite0008.janet +++ b/test/suite0008.janet @@ -309,7 +309,7 @@ neldb\0\0\0\xD8\x05printG\x01\0\xDE\xDE\xDE'\x03\0marshal_tes/\x02 # Issue 428 (var result nil) (defn f [] (yield {:a :ok})) -(assert-no-error "issue 428 1" (loop [{:a x} :generate (fiber/new f)] (set result x))) +(assert-no-error "issue 428 1" (loop [{:a x} :in (fiber/new f)] (set result x))) (assert (= result :ok) "issue 428 2") # Inline 3 argument get