Skip to content

Commit

Permalink
update if-let
Browse files Browse the repository at this point in the history
Fixes #1189
  • Loading branch information
primo-ppcg committed Jun 11, 2023
1 parent 7272f43 commit 42d76c9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/boot/boot.janet
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,11 @@
(do
(def bl (in bindings i))
(def br (in bindings (+ 1 i)))
(tuple 'if (tuple 'def bl br) (aux (+ 2 i)) fal))))
(if (idempotent? bl)
(tuple 'if (tuple 'def bl br) (aux (+ 2 i)) fal)
(tuple 'if (tuple 'def (def sym (gensym)) br)
(tuple 'upscope (tuple 'def bl sym) (aux (+ 2 i)))
fal)))))
(aux 0))

(defmacro when-let
Expand Down
1 change: 1 addition & 0 deletions test/suite-boot.janet
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
(assert (= (if-let [a my-array k (next a 5)] :t :f) :f) "if-let 4")
(assert (= (if-let [[a b] my-array] a) 1) "if-let 5")
(assert (= (if-let [{:a a :b b} {:a 1 :b 2}] b) 2) "if-let 6")
(assert (= (if-let [[a b] nil] :t :f) :f) "if-let 7")

(assert (= 14 (sum (map inc @[1 2 3 4]))) "sum map")
(def myfun (juxt + - * /))
Expand Down

0 comments on commit 42d76c9

Please sign in to comment.