Next: Introduction, Previous: (dir), Up: (dir) [Contents][Index]
This is the matrix-case Reference Manual, version 0.1.4, generated automatically by Declt version 4.0 beta 2 "William Riker" on Mon Aug 15 05:19:06 2022 GMT+0.
Next: Systems, Previous: The matrix-case Reference Manual, Up: The matrix-case Reference Manual [Contents][Index]
Control flow macros which writing nested CASE easily.
No such feature.
Hard to read/write.
Some pattern match library may provides same feature. But it is too much strong.
(matrix-typecase (:a :b)
((null null) :never)
((keyword keyword) :yes))
=> :YES
Integrated to popular utilities libraries. (e.g. alexandria)
Public domain
SBCL
TODO
Next: Files, Previous: Introduction, Up: The matrix-case Reference Manual [Contents][Index]
The main system appears first, followed by any subsystem dependency.
Control flow macros which writing nested CASE easily.
SATO Shinichi
(GIT git@github.com:hyotang666/matrix-case)
Public domain
0.1.4
matrix-case.lisp (file).
Next: Packages, Previous: Systems, Up: The matrix-case Reference Manual [Contents][Index]
Files are sorted by type and then listed depth-first from the systems components trees.
Next: matrix-case/matrix-case.lisp, Previous: Lisp, Up: Lisp [Contents][Index]
matrix-case (system).
Previous: matrix-case/matrix-case.asd, Up: Lisp [Contents][Index]
matrix-case (system).
Next: Definitions, Previous: Files, Up: The matrix-case Reference Manual [Contents][Index]
Packages are listed by definition order.
common-lisp.
Next: Indexes, Previous: Packages, Up: The matrix-case Reference Manual [Contents][Index]
Definitions are sorted by export status, category, package, and then by lexicographic order.
Next: Internals, Previous: Definitions, Up: Definitions [Contents][Index]
Previous: Public Interface, Up: Public Interface [Contents][Index]
# MATRIX-CASE, MATRIX-ECASE, MATRIX-CCASE
## [Macro] MATRIX-CASE MATRIX-ECASE MATRIX-CCASE
# Description: Like CL:CASE, but represents nested case.
“‘lisp
#?(op (0 1 2)
((0 0 0) :no)
((0 1 1) :no)
((0 1 2) :yes)
(otherwise :never))
=> :YES
“‘
“‘lisp
#?(matrix-case (0 1)
(((0 2 4 6 8) (1 3 5 7 9)) :yes)
(((0 2 4 6 8) (0 2 4 6 8)) :no)
(((1 3 5 7 9) (0 2 4 6 8)) :no))
=> :YES
“‘
### syntax
(MATRIX-CASE (&rest keyform) &body clause\*)
=> result
### Arguments and Values:
# keyform := a form; evaluated to produce a test-key.
# clause := ((test-key*) body)
test-key := an object produced by evaluating keyform.
body := an implicit PROGN.
# result := the values returned by the body in the matching clause.
# Affected By: none
# Side-Effects: none
# Notes:
# Exceptional-Situations:
# MATRIX-CASE, MATRIX-ECASE, MATRIX-CCASE
## [Macro] MATRIX-CASE MATRIX-ECASE MATRIX-CCASE
# Description: Like CL:CASE, but represents nested case.
“‘lisp
#?(op (0 1 2)
((0 0 0) :no)
((0 1 1) :no)
((0 1 2) :yes)
(otherwise :never))
=> :YES
“‘
“‘lisp
#?(matrix-case (0 1)
(((0 2 4 6 8) (1 3 5 7 9)) :yes)
(((0 2 4 6 8) (0 2 4 6 8)) :no)
(((1 3 5 7 9) (0 2 4 6 8)) :no))
=> :YES
“‘
### syntax
(MATRIX-CASE (&rest keyform) &body clause\*)
=> result
### Arguments and Values:
# keyform := a form; evaluated to produce a test-key.
# clause := ((test-key*) body)
test-key := an object produced by evaluating keyform.
body := an implicit PROGN.
# result := the values returned by the body in the matching clause.
# Affected By: none
# Side-Effects: none
# Notes:
# Exceptional-Situations:
# MATRIX-ETYPECASE, MATRIX-CTYPECASE
#### When any clause satisfies, an ERROR is signaled.
“‘lisp
#?(op (0)
((symbol) :never))
:signals ERROR
“‘
# MATRIX-CASE, MATRIX-ECASE, MATRIX-CCASE
## [Macro] MATRIX-CASE MATRIX-ECASE MATRIX-CCASE
# Description: Like CL:CASE, but represents nested case.
“‘lisp
#?(op (0 1 2)
((0 0 0) :no)
((0 1 1) :no)
((0 1 2) :yes)
(otherwise :never))
=> :YES
“‘
“‘lisp
#?(matrix-case (0 1)
(((0 2 4 6 8) (1 3 5 7 9)) :yes)
(((0 2 4 6 8) (0 2 4 6 8)) :no)
(((1 3 5 7 9) (0 2 4 6 8)) :no))
=> :YES
“‘
### syntax
(MATRIX-CASE (&rest keyform) &body clause\*)
=> result
### Arguments and Values:
# keyform := a form; evaluated to produce a test-key.
# clause := ((test-key*) body)
test-key := an object produced by evaluating keyform.
body := an implicit PROGN.
# result := the values returned by the body in the matching clause.
# Affected By: none
# Side-Effects: none
# Notes:
# Exceptional-Situations:
# MATRIX-ETYPECASE, MATRIX-CTYPECASE
#### When any clause satisfies, an ERROR is signaled.
“‘lisp
#?(op (0)
((symbol) :never))
:signals ERROR
“‘
# MATRIX-TYPECASE, MATRIX-ETYPECASE, MATRIX-CTYPECASE
## [Macro] MATRIX-TYPECASE MATRIX-ETYPECASE MATRIX-CTYPECASE
# Description: Like CL:TYPECASE, but represents nested typecases.
“‘lisp
#?(let((a 0))
(op(a ’key)
((symbol integer):never)
((integer symbol):yes!)
(otherwise :no!)))
=> :YES!
“‘
#### Only one cluase’s body will be evaluated.
“‘lisp
#?(op (0 ’sym 1)
((symbol symbol symbol) (princ :sss))
((symbol symbol integer) (princ :ssi))
((symbol integer symbol) (princ :sis))
((symbol integer integer) (princ :sii))
((integer symbol integer) (princ :yes))
((integer symbol symbol) (princ :iss))
((integer integer integer) (princ :iii))
((integer integer symbol) (princ :iis))
(otherwise (princ :otherwise)))
:outputs "YES"
“‘
#### Of course, we can use compound type specifier.
“‘lisp
#?(op (0)
(((and integer (eql 1))) :no)
(((member 0 2 4 6 8)) :yes))
=> :YES
“‘
#### T as wildcard
“‘lisp
#?(op ("hoge" 0)
((t symbol) :no)
((t fixnum) :yes)
((string string) :no))
=> :yes
“‘
#### NOTE! wildcard is treated as last resort.
“‘lisp
#?(op ("1" "2")
((t string) :no)
((string string) :yes))
=> :yes
“‘
“‘lisp
#?(op ("1" "2")
((string t) :no)
((string string) :yes))
=> :yes
“‘
#### NOTE! Each clause is tested left to right order.
“‘lisp
#?(op (:a :b)
((null null) :no)
((atom atom) :yes))
=> :yes
“‘
### syntax
(MATRIX-TYPECASE targets &body clauses)
=> result
### Arguments and Values:
# targets := (target*)
target := one lisp form
#### every TARGET forms are evaluated only once.
“‘lisp
#?(op ((princ 0) (princ 1))
((symbol symbol) :no)
((integer symbol) :no)
((symbol integer) :no)
(otherwise :no))
:outputs "01"
“‘
# clauses := ((typespecifier+) &body body)
typespecifier := see hyperspec
body := implicit PROGN
# result := T
# Affected By: none
# Side-Effects: none
# Notes:
#### Empty TARGETS is valid but, in such case CLAUSES must empty.
#### Such form evaluated to be NIL by macro expansion.
“‘lisp
#?(op () ())
=> NIL
“‘
“‘lisp
#?(op () ())
:expanded-to NIL
“‘
“‘lisp
#?(op ())
=> NIL
“‘
“‘lisp
#?(op ())
:expanded-to NIL
“‘
“‘lisp
#?(op)
:signals ERROR
“‘
#### ECL/16.1.3 specific issue.
“‘lisp
#?(flet ((doit ()
(op (’(elt))
((atom) :atom)
(otherwise :other))))
(doit))
=> :other
“‘
# Exceptional-Situations:
#### when TARGETS length and each TYPE-SPECIFIERS length is different,
#### an error is signaled.
“‘lisp
#?(op (0)
((symbol integer) :error))
:signals ERROR
“‘
“‘lisp
#?(op (0 :hoge)
((integer) :error))
:signals ERROR
“‘
#### others
# MATRIX-TYPECASE
#### Default return value is NIL.
“‘lisp
#?(matrix-typecase (0)
((symbol) :no))
=> NIL
“‘
#### Expanded examples.
“‘lisp
#?(matrix-typecase (0)
((integer) :yes)
(otherwise :no))
:expanded-to (let ((var 0))
(typecase var
(integer :yes)
(otherwise :no)))
“‘
“‘lisp
#?(matrix-typecase (0 ’sym)
((symbol integer) :no)
((integer symbol) :yes)
(otherwise :never))
:expanded-to (let ((var1 0))
(typecase var1
(symbol (let ((var2 ’sym))
(typecase var2
(integer :no)
(otherwise :never))))
(integer (let ((var3 ’sym))
(typecase var3
(symbol :yes)
(otherwise :never))))
(otherwise :never)))
“‘
Previous: Public Interface, Up: Definitions [Contents][Index]
Next: Ordinary functions, Previous: Internals, Up: Internals [Contents][Index]
Move T clause to the last as otherwise clause.
Remove prefix "E" or "C", if otherwise clause exists.
Previous: Definitions, Up: The matrix-case Reference Manual [Contents][Index]
Jump to: | C D F I M |
---|
Jump to: | C D F I M |
---|
Jump to: | F M P S |
---|
Jump to: | F M P S |
---|