File tree Expand file tree Collapse file tree 3 files changed +4
-4
lines changed Expand file tree Collapse file tree 3 files changed +4
-4
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
22
22
* Generate Python classes for ` deftype* ` and ` reify* ` forms using modern ` @attr.define ` , ` @attr.frozen ` , and ` @attr.field ` APIs (#799 )
23
23
* Generate Protocol functions with nicer names based on the protocol function and dispatch type (#803 )
24
24
* Loosen the dependency specification for Immutables and Pyrsistent to allow for a wider version range (#805 )
25
+ * Allow ` case ` forms with only a default expression (#807 )
25
26
26
27
### Fixed
27
28
* Fix issue with ` (count nil) ` throwing an exception (#759 )
Original file line number Diff line number Diff line change 3402
3402
(defmacro case
3403
3403
"Switch on ``expr`` to return a matching clause from the set of input clauses.
3404
3404
3405
- The input expression may be any valid Basilisp expression.
3405
+ The input expression may be any valid Basilisp expression. A single default expression
3406
+ can follow the clauses, and its value will be returned if no clause matches.
3406
3407
3407
3408
The clauses are pairs of a matching value and a return value. The matching values are
3408
3409
not evaluated and must be compile-time constants. Symbols will not be resolved. Lists
3409
3410
may be passed to match multiple compile time values to a single return value. The
3410
3411
dispatch is done in constant time."
3411
3412
[expr & clauses]
3412
- (when (< (count clauses) 2)
3413
- (throw (ex-info "case expression must have at least one clause"
3414
- {:clauses clauses})))
3415
3413
(let [default (if (odd? (count clauses))
3416
3414
(last clauses)
3417
3415
:basilisp.core.case/no-default)
Original file line number Diff line number Diff line change 326
326
(is (= "also no" (case 'c :a "no" (b c d) "also no" "duh")))
327
327
(is (= "also no" (case 'd :a "no" (b c d) "also no" "duh")))
328
328
(is (= "duh" (case 'e :a "no" (b c d) "also no" "duh")))
329
+ (is (= 0 (case 1 0)))
329
330
(let [out* (atom [])]
330
331
(is (= 2 (case :2
331
332
:1 (do (swap! out* conj 1) 1)
You can’t perform that action at this time.
0 commit comments