File tree Expand file tree Collapse file tree 3 files changed +26
-12
lines changed Expand file tree Collapse file tree 3 files changed +26
-12
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
11
11
### Fixed
12
12
* Fix a bug where tags in data readers were resolved as Vars within syntax quotes, rather than using standard data readers rules (#1129 )
13
13
* Fix a bug where ` keyword ` and ` symbol ` functions did not treat string arguments as potentially namespaced (#1131 )
14
+ * Fix a bug where ` condp ` would throw an exception if a result expression was ` nil ` (#1137 )
14
15
15
16
## [ v0.3.2]
16
17
### Added
Original file line number Diff line number Diff line change 3565
3565
- ``test-expr :>> result-fn`` where :>> is a keyword literal
3566
3566
3567
3567
For the ternary expression clause, the unary ``result-fn`` will be called with the
3568
- result of the predicate."
3568
+ result of the predicate.
3569
+
3570
+ A single final expression can be included at the end with no test expression which
3571
+ will be returned if no other clause matches the predicate. If no default is provided
3572
+ and no clause matches the predicate, a ``ValueError`` will be thrown."
3569
3573
[pred expr & clauses]
3570
3574
(when (seq clauses)
3571
3575
(let [test-expr (first clauses)
3574
3578
(let [result (first remaining)
3575
3579
remaining (rest remaining)]
3576
3580
(cond
3577
- (= result :>>) `(let [res# ~(list pred test-expr expr)]
3578
- (if res#
3579
- (~(first remaining) res# )
3580
- (condp ~ pred ~ expr ~@(rest remaining))))
3581
- result `(if ~(list pred test-expr expr)
3582
- ~result
3583
- (condp ~pred ~expr ~@remaining))
3584
- :else (throw
3585
- (ex-info "expected result expression"
3586
- {:test test- expr} ))))
3581
+ (not (seq remaining)) `(throw
3582
+ (python/ValueError
3583
+ (str "Expected result expression for condp " {:test ~test-expr})) )
3584
+ (= result :>>) `(let [res# ~(list pred test- expr expr)]
3585
+ (if res#
3586
+ (~(first remaining) res#)
3587
+ (condp ~pred ~expr ~@(rest remaining)) ))
3588
+ :else `(if ~(list pred test-expr expr)
3589
+ ~result
3590
+ (condp ~pred ~ expr ~@remaining ))))
3587
3591
test-expr))))
3588
3592
3589
3593
(defmacro declare
Original file line number Diff line number Diff line change 347
347
(is (= :a (condp = "a"
348
348
"b" :b
349
349
"c" :c
350
- :a))))
350
+ :a)))
351
+ (is (nil? (condp = "a"
352
+ "b" :b
353
+ "a" nil
354
+ "c" :c
355
+ :a)))
356
+ (is (thrown? python/ValueError
357
+ (condp = "a"
358
+ "b" :b
359
+ "c" :c))))
351
360
352
361
(testing "condp result function"
353
362
(is (= :a (condp some [1 8 10 12]
You can’t perform that action at this time.
0 commit comments