Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
* Fix a bug in `defn` where the `attr-map?` and function metdata were merged into a seq instead of a map, causing `macroexpand` to fail in some cases (#1186)
* Fix a bug where `basilisp.process/exec` threw an exception when inheriting the stdout stream from the current process (#1190)
* Fix a bug where `condp` threw an exception in certain cases (#1194)

## [v0.3.5]
### Changed
Expand Down
26 changes: 16 additions & 10 deletions src/basilisp/core.lpy
Original file line number Diff line number Diff line change
Expand Up @@ -3573,16 +3573,22 @@
(let [result (first remaining)
remaining (rest remaining)]
(cond
(not (seq remaining)) `(throw
(python/ValueError
(str "Expected result expression for condp " {:test ~test-expr})))
(= result :>>) `(let [res# ~(list pred test-expr expr)]
(if res#
(~(first remaining) res#)
(condp ~pred ~expr ~@(rest remaining))))
:else `(if ~(list pred test-expr expr)
~result
(condp ~pred ~expr ~@remaining))))
(= result :>>) `(let [res# ~(list pred test-expr expr)]
(if res#
(~(first remaining) res#)
(condp ~pred ~expr ~@(rest remaining))))
(seq remaining) `(if ~(list pred test-expr expr)
~result
(condp ~pred ~expr ~@remaining))
(and result
(not (seq remaining))) `(if ~(list pred test-expr expr)
~result
(throw
(python/ValueError
(str "Expected result expression for condp " {:test ~test-expr}))))
:else `(throw
(python/ValueError
(str "Expected result expression for condp " {:test ~test-expr})))))
test-expr))))

(defmacro declare
Expand Down
5 changes: 5 additions & 0 deletions tests/basilisp/test_core_macros.lpy
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,11 @@
(deftest condp-test
(testing "condp result value"
(is (= :a (condp = "a" :a)))
(is (= :a (condp = "a"
"a" :a)))
(is (= :a (condp = "a"
"a" :a
:b)))
(is (= :a (condp = "a"
"b" :b
:a)))
Expand Down
Loading