The matrix-case Reference Manual

This is the matrix-case Reference Manual, version 0.1.4, generated automatically by Declt version 4.0 beta 2 "William Riker" on Sun Sep 15 06:02:54 2024 GMT+0.

Table of Contents


1 Introduction


2 Systems

The main system appears first, followed by any subsystem dependency.


2.1 matrix-case

Control flow macros which writing nested CASE easily.

Author

SATO Shinichi

Source Control

(GIT git@github.com:hyotang666/matrix-case)

Bug Tracker

https://github.com/hyotang666/matrix-case/issues

License

Public domain

Version

0.1.4

Source

matrix-case.asd.

Child Component

matrix-case.lisp (file).


3 Files

Files are sorted by type and then listed depth-first from the systems components trees.


3.1 Lisp


3.1.1 matrix-case/matrix-case.asd

Source

matrix-case.asd.

Parent Component

matrix-case (system).

ASDF Systems

matrix-case.


3.1.2 matrix-case/matrix-case.lisp

Source

matrix-case.asd.

Parent Component

matrix-case (system).

Packages

matrix-case.

Public Interface
Internals

4 Packages

Packages are listed by definition order.


4.1 matrix-case

Source

matrix-case.lisp.

Use List

common-lisp.

Public Interface
Internals

5 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


5.1 Public Interface


5.1.1 Macros

Macro: matrix-case ((&rest targets) &body clauses)

# 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:

Package

matrix-case.

Source

matrix-case.lisp.

Macro: matrix-ccase ((&rest targets) &body clauses)

# 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:

Package

matrix-case.

Source

matrix-case.lisp.

Macro: matrix-ctypecase ((&rest targets) &body clauses)

# MATRIX-ETYPECASE, MATRIX-CTYPECASE

#### When any clause satisfies, an ERROR is signaled.

“‘lisp
#?(op (0)
((symbol) :never))
:signals ERROR
“‘

Package

matrix-case.

Source

matrix-case.lisp.

Macro: matrix-ecase ((&rest targets) &body clauses)

# 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:

Package

matrix-case.

Source

matrix-case.lisp.

Macro: matrix-etypecase ((&rest targets) &body clauses)

# MATRIX-ETYPECASE, MATRIX-CTYPECASE

#### When any clause satisfies, an ERROR is signaled.

“‘lisp
#?(op (0)
((symbol) :never))
:signals ERROR
“‘

Package

matrix-case.

Source

matrix-case.lisp.

Macro: matrix-typecase ((&rest targets) &body clauses)

# 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)))
“‘

Package

matrix-case.

Source

matrix-case.lisp.


5.2 Internals


5.2.1 Macros

Macro: defmatrix (underlying)
Package

matrix-case.

Source

matrix-case.lisp.


5.2.2 Ordinary functions

Function: canonicalize (alist)

Move T clause to the last as otherwise clause.

Package

matrix-case.

Source

matrix-case.lisp.

Function: fix-underlying (underlying otherwisep)

Remove prefix "E" or "C", if otherwise clause exists.

Package

matrix-case.

Source

matrix-case.lisp.

Function: integrate-candidates (clauses underlying)
Package

matrix-case.

Source

matrix-case.lisp.

Function: matrix (underlying targets clauses default)
Package

matrix-case.

Source

matrix-case.lisp.


Appendix A Indexes


A.1 Concepts


A.3 Variables