From 1077efd03a9699132735f6c1b543106070a18d24 Mon Sep 17 00:00:00 2001 From: primo-ppcg Date: Sun, 11 Jun 2023 16:38:04 +0700 Subject: [PATCH] update if-let Fixes #1189 --- src/boot/boot.janet | 6 +++++- test/suite-boot.janet | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 602c8a2e8..4c158f443 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -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 (symbol? bl) + (tuple 'if (tuple 'def bl br) (aux (+ 2 i)) fal) + (tuple 'if (tuple 'def (def sym (gensym)) br) + (tuple 'do (tuple 'def bl sym) (aux (+ 2 i))) + fal))))) (aux 0)) (defmacro when-let diff --git a/test/suite-boot.janet b/test/suite-boot.janet index 17cdb0d51..18a3074c3 100644 --- a/test/suite-boot.janet +++ b/test/suite-boot.janet @@ -129,6 +129,8 @@ (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 (= (if-let [a true b false] b a) true) "if-let 8") (assert (= 14 (sum (map inc @[1 2 3 4]))) "sum map") (def myfun (juxt + - * /))