mirror of
				https://github.com/janet-lang/janet
				synced 2025-10-31 07:33:01 +00:00 
			
		
		
		
	Remove :generate verb from loop.
Instead, one case use `:in` as with otehr data structures.
This commit is contained in:
		| @@ -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`. | ||||
|   | ||||
| @@ -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." | ||||
|   | ||||
| @@ -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") | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Calvin Rose
					Calvin Rose