1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-24 17:27:18 +00:00

Add where clause to list comprehension.

This commit is contained in:
Calvin Rose 2018-05-23 23:43:48 -04:00
parent b09bf72490
commit 8bcb5e0019
2 changed files with 34 additions and 31 deletions

View File

@ -231,7 +231,10 @@ value."
(def bindings (get head1 i))
(def verb (ast.unwrap1 (get head1 (+ i 1))))
(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
(def [start end _inc] (ast.unwrap1 object))
(def inc (if _inc _inc 1))
@ -262,7 +265,7 @@ value."
(tuple 'def bindings (tuple get $indexed $i))
(doone (+ i 3))
(tuple ':= $i (tuple + 1 $i)))))
(error ("unexpected loop verb: " verb))))))
(error ("unexpected loop verb: " verb)))))))
(doone 0))
(defmacro for

View File

@ -42,7 +42,7 @@
(defn assert-many [f n e]
(var good true)
(for [i 0 n]
(loop [i :range [0 n]]
(if (not (f i))
(:= good false)))
(assert good e))