From 53cf2be4405729df5112b184904b1b2f3c98c621 Mon Sep 17 00:00:00 2001 From: Chris Rink Date: Fri, 29 Nov 2024 07:14:12 -0500 Subject: [PATCH 1/2] Fix a bug with `case` macro --- CHANGELOG.md | 1 + src/basilisp/core.lpy | 2 +- tests/basilisp/test_core_macros.lpy | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index baf4344a..b89d1b8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Fixed * Fix a bug where `#` characters were not legal in keywords and symbols (#1149) + * Fix a bug where seqs were not considered valid input for matching clauses of the `case` macro (#1148) ## [v0.3.3] ### Added diff --git a/src/basilisp/core.lpy b/src/basilisp/core.lpy index 57a86f4c..85d8a257 100644 --- a/src/basilisp/core.lpy +++ b/src/basilisp/core.lpy @@ -3537,7 +3537,7 @@ (mapcat (fn [pair] (let [binding (first pair) expr `(fn [] ~(second pair))] - (if (list? binding) + (if (seq? binding) (map #(vector (list 'quote %) expr) binding) [[(list 'quote binding) expr]]))) (partition 2 diff --git a/tests/basilisp/test_core_macros.lpy b/tests/basilisp/test_core_macros.lpy index f57cbb7b..d54a405f 100644 --- a/tests/basilisp/test_core_macros.lpy +++ b/tests/basilisp/test_core_macros.lpy @@ -316,6 +316,11 @@ (let [l #py [1 2 3]] (is (= 6 (areduce l idx ret 0 (+ ret (aget l idx))))))) +(defmacro case-with-seq + [] + (case :val + ~(seq [:val]) :found)) + (deftest case-test (is (= "yes" (case :a :b "nope" :c "mega nope" :a "yes" "nerp"))) (is (= "nope" (case :b :b "nope" :c "mega nope" :a "yes" "nerp"))) @@ -328,6 +333,7 @@ (is (= "also no" (case 'd :a "no" (b c d) "also no" "duh"))) (is (= "duh" (case 'e :a "no" (b c d) "also no" "duh"))) (is (= 0 (case 1 0))) + (is (= :found (case-with-seq))) (let [out* (atom [])] (is (= 2 (case :2 :1 (do (swap! out* conj 1) 1) From 4c2e711a1fb37b020a1c32f9e817a4a63950592f Mon Sep 17 00:00:00 2001 From: Chris Rink Date: Fri, 29 Nov 2024 07:18:16 -0500 Subject: [PATCH 2/2] Goofed it --- tests/basilisp/test_core_macros.lpy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/basilisp/test_core_macros.lpy b/tests/basilisp/test_core_macros.lpy index d54a405f..68685902 100644 --- a/tests/basilisp/test_core_macros.lpy +++ b/tests/basilisp/test_core_macros.lpy @@ -318,8 +318,8 @@ (defmacro case-with-seq [] - (case :val - ~(seq [:val]) :found)) + `(case :val + ~(seq [:val]) :found)) (deftest case-test (is (= "yes" (case :a :b "nope" :c "mega nope" :a "yes" "nerp")))