Skip to content

Commit

Permalink
Merge pull request #170 from kilianmh/feat/ccase-let,ctypecase-let
Browse files Browse the repository at this point in the history
Feat: Add ccase-let, ctypecase-let
  • Loading branch information
ruricolist committed Apr 25, 2024
2 parents 861bfcd + 0324fd5 commit 6b9fbc8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
12 changes: 12 additions & 0 deletions control-flow.lisp
Expand Up @@ -515,6 +515,12 @@ Burson."
(case ,var
,@cases)))

(defmacro ccase-let ((var expr) &body cases)
"Like (let ((VAR EXPR)) (ccase VAR ...)), with VAR correctable."
`(let ((,var ,expr))
(ccase ,var
,@cases)))

(defmacro ecase-let ((var expr) &body cases)
"Like (let ((VAR EXPR)) (ecase VAR ...)), with VAR read-only."
`(let1 ,var ,expr
Expand All @@ -527,6 +533,12 @@ Burson."
(typecase ,var
,@cases)))

(defmacro ctypecase-let ((var expr) &body cases)
"Like (let ((VAR EXPR)) (ctypecase VAR ...)), with VAR correctable."
`(let ((,var ,expr))
(ctypecase ,var
,@cases)))

(defmacro etypecase-let ((var expr) &body cases)
"Like (let ((VAR EXPR)) (etypecase VAR ...)), with VAR read-only."
`(let1 ,var ,expr
Expand Down
2 changes: 2 additions & 0 deletions package.lisp
Expand Up @@ -145,7 +145,9 @@
#:ecase-let
#:cond-let
#:case-let
#:ccase-let
#:typecase-let
#:ctypecase-let
#:etypecase-let
#:bcond
#:comment
Expand Down
19 changes: 19 additions & 0 deletions tests/control-flow.lisp
Expand Up @@ -189,6 +189,14 @@
(case-let (x 16)
(0 3) (1 (1+ x)) (t 5)))))

(test ccase-let
(is (eql 2
(ccase-let (x 1)
(0 3) (1 (1+ x)) (t 5))))
(signals type-error
(ccase-let (x 17)
(0 x) (1 (1+ x)))))

(test ecase-let
(is (eql 2
(ecase-let (x 1)
Expand All @@ -207,6 +215,17 @@
(integer "not")
(string (concatenate 'string y "-here"))))))

(test ctypecase-let
(is (eql 'asdf
(ctypecase-let (x 'asdf)
(string 20)
(integer :sdf)
(symbol x))))
(signals type-error
(ctypecase-let (y 'test-symbol)
(integer "not")
(string (concatenate 'string y "-here")))))

(test etypecase-let
(is (eql 2
(etypecase-let (x 'asdf)
Expand Down

0 comments on commit 6b9fbc8

Please sign in to comment.