1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-25 07:50:27 +00:00

add :unless loop modifier

This commit is contained in:
primo-ppcg 2023-09-13 15:21:46 +07:00
parent ff18b92eb0
commit db366558e7
2 changed files with 6 additions and 0 deletions

View File

@ -473,6 +473,7 @@
:repeat (with-syms [iter] :repeat (with-syms [iter]
~(do (var ,iter ,verb) (while (> ,iter 0) ,rest (-- ,iter)))) ~(do (var ,iter ,verb) (while (> ,iter 0) ,rest (-- ,iter))))
:when ~(when ,verb ,rest) :when ~(when ,verb ,rest)
:unless ~(unless ,verb ,rest)
(error (string "unexpected loop modifier " binding)))))) (error (string "unexpected loop modifier " binding))))))
# 3 term expression # 3 term expression

View File

@ -186,6 +186,11 @@
(assert (= txs [[-1 -1] [-1 0] [-1 1] [0 -1] [0 1] [1 -1] [1 0] [1 1]]) (assert (= txs [[-1 -1] [-1 0] [-1 1] [0 -1] [0 1] [1 -1] [1 0] [1 1]])
"nested seq") "nested seq")
# :unless modifier
(assert (deep= (seq [i :range [0 10] :unless (odd? i)] i)
@[0 2 4 6 8])
":unless modifier")
# 515891b03 # 515891b03
(assert (deep= (tabseq [i :in (range 3)] i (* 3 i)) (assert (deep= (tabseq [i :in (range 3)] i (* 3 i))
@{0 0 1 3 2 6})) @{0 0 1 3 2 6}))