The matrix-case Reference Manual

Table of Contents

Next: , Previous: , Up: (dir)   [Contents][Index]

The matrix-case Reference Manual

This is the matrix-case Reference Manual, version 0.0.7, generated automatically by Declt version 3.0 "Montgomery Scott" on Fri Jun 26 11:43:22 2020 GMT+0.


Next: , Previous: , Up: Top   [Contents][Index]

1 Introduction

MATRIX-CASE 0.0.6

What is this?

Control flow macros which writing nested CASE easily.

Current lisp world

No such feature.

Issues

Hard to read/write.

Some pattern match library may provides same feature. But it is too much strong.

Proposal

Usage

(matrix-typecase (:a :b)
  ((null null) :never)
  ((keyword keyword) :yes))
=> :YES

From developer

Product's goal

Integrated to popular utilities libraries. (e.g. alexandria)

License

Public domain

Developed with

SBCL

Tested with

Installation

TODO


Next: , Previous: , Up: Top   [Contents][Index]

2 Systems

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


Previous: , Up: Systems   [Contents][Index]

2.1 matrix-case

Author

Shinichi Sato

License

Public domain

Description

Control flow macros which writing nested CASE easily.

Version

0.0.7

Source

matrix-case.asd (file)

Component

matrix-case.lisp (file)


Next: , Previous: , Up: Top   [Contents][Index]

3 Files

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


Previous: , Up: Files   [Contents][Index]

3.1 Lisp


Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.1 matrix-case.asd

Location

matrix-case.asd

Systems

matrix-case (system)


Previous: , Up: Lisp files   [Contents][Index]

3.1.2 matrix-case/matrix-case.lisp

Parent

matrix-case (system)

Location

matrix-case.lisp

Packages

matrix-case

Exported Definitions
Internal Definitions

Next: , Previous: , Up: Top   [Contents][Index]

4 Packages

Packages are listed by definition order.


Previous: , Up: Packages   [Contents][Index]

4.1 matrix-case

Source

matrix-case.lisp (file)

Use List

common-lisp

Exported Definitions
Internal Definitions

Next: , Previous: , Up: Top   [Contents][Index]

5 Definitions

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


Next: , Previous: , Up: Definitions   [Contents][Index]

5.1 Exported definitions


Previous: , Up: Exported definitions   [Contents][Index]

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 (file)

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 (file)

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 (file)

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 (file)

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 (file)

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)
(t :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)
(t :never))))
(integer (let ((var3 ’sym))
(typecase var3
(symbol :yes)
(t :never))))
(t :never)))
“‘

Package

matrix-case

Source

matrix-case.lisp (file)


Previous: , Up: Definitions   [Contents][Index]

5.2 Internal definitions


Next: , Previous: , Up: Internal definitions   [Contents][Index]

5.2.1 Macros

Macro: defmatrix UNDERLYING
Package

matrix-case

Source

matrix-case.lisp (file)


Previous: , Up: Internal definitions   [Contents][Index]

5.2.2 Functions

Function: canonicalize ALIST
Package

matrix-case

Source

matrix-case.lisp (file)

Function: integrate-candidates CLAUSES UNDERLYING
Package

matrix-case

Source

matrix-case.lisp (file)

Function: matrix UNDERLYING TARGETS CLAUSES DEFAULT
Package

matrix-case

Source

matrix-case.lisp (file)


Previous: , Up: Top   [Contents][Index]

Appendix A Indexes


Next: , Previous: , Up: Indexes   [Contents][Index]

A.1 Concepts

Jump to:   F   L   M  
Index Entry  Section

F
File, Lisp, matrix-case.asd: The matrix-case․asd file
File, Lisp, matrix-case/matrix-case.lisp: The matrix-case/matrix-case․lisp file

L
Lisp File, matrix-case.asd: The matrix-case․asd file
Lisp File, matrix-case/matrix-case.lisp: The matrix-case/matrix-case․lisp file

M
matrix-case.asd: The matrix-case․asd file
matrix-case/matrix-case.lisp: The matrix-case/matrix-case․lisp file

Jump to:   F   L   M  

Next: , Previous: , Up: Indexes   [Contents][Index]

A.2 Functions

Jump to:   C   D   F   I   M  
Index Entry  Section

C
canonicalize: Internal functions

D
defmatrix: Internal macros

F
Function, canonicalize: Internal functions
Function, integrate-candidates: Internal functions
Function, matrix: Internal functions

I
integrate-candidates: Internal functions

M
Macro, defmatrix: Internal macros
Macro, matrix-case: Exported macros
Macro, matrix-ccase: Exported macros
Macro, matrix-ctypecase: Exported macros
Macro, matrix-ecase: Exported macros
Macro, matrix-etypecase: Exported macros
Macro, matrix-typecase: Exported macros
matrix: Internal functions
matrix-case: Exported macros
matrix-ccase: Exported macros
matrix-ctypecase: Exported macros
matrix-ecase: Exported macros
matrix-etypecase: Exported macros
matrix-typecase: Exported macros

Jump to:   C   D   F   I   M  

Next: , Previous: , Up: Indexes   [Contents][Index]

A.3 Variables


Previous: , Up: Indexes   [Contents][Index]

A.4 Data types

Jump to:   M   P   S  
Index Entry  Section

M
matrix-case: The matrix-case system
matrix-case: The matrix-case package

P
Package, matrix-case: The matrix-case package

S
System, matrix-case: The matrix-case system

Jump to:   M   P   S