mirror of
https://github.com/janet-lang/janet
synced 2024-11-28 11:09:54 +00:00
Add where clause to list comprehension.
This commit is contained in:
parent
b09bf72490
commit
8bcb5e0019
@ -231,7 +231,10 @@ value."
|
|||||||
(def bindings (get head1 i))
|
(def bindings (get head1 i))
|
||||||
(def verb (ast.unwrap1 (get head1 (+ i 1))))
|
(def verb (ast.unwrap1 (get head1 (+ i 1))))
|
||||||
(def object (ast.unwrap1 (get head1 (+ i 2))))
|
(def object (ast.unwrap1 (get head1 (+ i 2))))
|
||||||
(switch verb
|
(if (= (ast.unwrap1 bindings) :where)
|
||||||
|
(tuple 'if verb (doone (+ i 2)))
|
||||||
|
(switch
|
||||||
|
verb
|
||||||
:range (do
|
:range (do
|
||||||
(def [start end _inc] (ast.unwrap1 object))
|
(def [start end _inc] (ast.unwrap1 object))
|
||||||
(def inc (if _inc _inc 1))
|
(def inc (if _inc _inc 1))
|
||||||
@ -262,7 +265,7 @@ value."
|
|||||||
(tuple 'def bindings (tuple get $indexed $i))
|
(tuple 'def bindings (tuple get $indexed $i))
|
||||||
(doone (+ i 3))
|
(doone (+ i 3))
|
||||||
(tuple ':= $i (tuple + 1 $i)))))
|
(tuple ':= $i (tuple + 1 $i)))))
|
||||||
(error ("unexpected loop verb: " verb))))))
|
(error ("unexpected loop verb: " verb)))))))
|
||||||
(doone 0))
|
(doone 0))
|
||||||
|
|
||||||
(defmacro for
|
(defmacro for
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
|
|
||||||
(defn assert-many [f n e]
|
(defn assert-many [f n e]
|
||||||
(var good true)
|
(var good true)
|
||||||
(for [i 0 n]
|
(loop [i :range [0 n]]
|
||||||
(if (not (f i))
|
(if (not (f i))
|
||||||
(:= good false)))
|
(:= good false)))
|
||||||
(assert good e))
|
(assert good e))
|
||||||
|
Loading…
Reference in New Issue
Block a user