This is the optima Reference Manual, version 1.0, generated automatically by Declt version 4.0 beta 2 "William Riker" on Sun Sep 15 06:16:39 2024 GMT+0.
The main system appears first, followed by any subsystem dependency.
optima
Optimized Pattern Matching Library
Tomohiro Matsuyama
LLGPL
optima is a fast pattern matching library which
uses optimizing techniques widely used in the functional programming
world. See the following references for more details:
* [Optimizing Pattern Matching](http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.6.5507) by Fabrice Le Fessant, Luc Maranget
* [The Implementation of Functional Programming Languages](http://research.microsoft.com/en-us/um/people/simonpj/papers/slpj-book-1987/) by Simon Peyton Jones
Pattern Language
—————-
A pattern specifier, or a pattern for short ambiguous, is an
expression that describes how a value matches some
specification. Pattern specifiers are defined as follows:
pattern-specifier ::= constant-pattern
| variable-pattern
| place-pattern
| guard-pattern
| not-pattern
| or-pattern
| and-pattern
| constructor-pattern
| derived-pattern
constant-pattern ::= t | nil
| keyword
| atom-except-symbol
| (quote VALUE)
variable-pattern ::= SYMBOL | (variable SYMBOL)
place-pattern ::= (place SYMBOL)
guard-pattern ::= (guard PATTERN TEST-FORM)
not-pattern ::= (not PATTERN)
or-pattern ::= (or PATTERN*)
and-pattern ::= (and PATTERN*)
constructor-pattern ::= (NAME ARG*)
derived-pattern ::= (NAME PATTERN*)
### Constant-Pattern
A constant-pattern matches the constant itself.
Examples:
(match 1 (1 2)) => 2
(match "foo" ("foo" "bar")) => "bar"
(match ’(1) (’(1) 2)) => 2
### Variable-Pattern
A variable-pattern matches any value and binds the value to the
variable. "_" and "otherwise" are special variable-patterns (a.k.a
wildcard-pattern) which match any value but don’t bind.
Examples:
(match 1 (x x)) => 1
(match 1 (_ 2)) => 2
(match 1
(2 2)
(otherwise ’otherwise))
=> OTHERWISE
### Place-Pattern
A place-pattern matches any value, in the same way as
variable-patterns do, but binds the value by using SYMBOL-MACROLET.
Examples:
(defvar c (cons 1 2))
(match c ((cons (place x) y) (incf x) (incf y)))
c
=> (2 . 2)
### Guard-Pattern
A guard-pattern is a special pattern that tests whether TEST-FORM is
satisfied in the current matching context.
Examples:
(match 1 ((guard x (eql x 2)) t))
=> NIL
(match 1 ((guard x (eql x 1)) t))
=> T
### Not-Pattern
A not-pattern matches a value that is not matched with sub-PATTERN.
Examples:
(match 1 ((not 2) 3)) => 3
(match 1 ((not (not 1)) 1)) => 1
### Or-Pattern
An or-pattern matches a value that is matched with one of
sub-PATTERNs.
Examples:
(match ’(2 . 1) ((or (cons 1 x) (cons 2 x)) x))
=> 1
### And-Pattern
An and-pattern matches a value that is matched with all of its
sub-PATTERNs. The most common use case is to match a value and bind
the value to a variable.
Examples:
(match 1 ((and 1 x) x))
=> 1
### Constructor-Pattern
A constructor-pattern matches the sub-components of a value based on
its structure. The following constructors are available:
#### CONS
Syntax:
cons-constructor-pattern ::= (cons CAR-PATTERN CDR-PATTERN)
Examples:
(match ’(1 . 2)
((cons a b) (+ a b)))
=> 3
#### ASSOC
Syntax:
assoc-constructor-pattern ::= (assoc ITEM PATTERN &key key test)
Examples:
(match ’((1 . :one))
((assoc 1 x) x))
=> :ONE
(match ’((1 . :one) (2 . :two))
((assoc 2 x) x))
=> :TWO
(match ’(1 (2 . 3))
((assoc 2 x) x))
=> 3
(match ’(("a" . 123))
((assoc "A" 123 :test #’string-equal) t))
=> T
#### PROPERTY
Syntax:
property-constructor-pattern ::= (property KEY PATTERN)
Examples:
(match ’(:a 1)
((property :a x) x))
=> 1
(match ’(:a 1 :b 2)
((property :b x) x))
=> 2
(match ’(:a 1 2)
((property :a x) x))
=> 1
#### VECTOR
Syntax:
vector-constructor-pattern ::= (vector PATTERN*)
Examples:
(match #(1 2)
((vector a b) (+ a b)))
=> 3
#### SIMPLE-VECTOR
Syntax:
simple-vector-constructor-pattern ::= (simple-vector PATTERN*)
Examples:
(match #(1 2)
((simple-vector a b) (+ a b)))
=> 3
#### CLASS
Matches an instance of a given subclass of standard-class, as well as
the instance’s slots.
Syntax:
class-constructor-pattern ::= (class NAME slot*)
| (NAME slot*)
slot ::= SLOT-NAME
| (SLOT-NAME PATTERN*)
CLASS can be omitted. If slot is a symbol, then it will be regarded
as (slot slot). If more than one PATTERN is given, then they will be
wrapped by and-pattern like (and PATTERN*).
Examples:
(defclass point ()
((x :initarg :x)
(y :initarg :y)))
(defvar p (make-instance ’point :x 1 :y 2))
(match p
((point x y) (list x y)))
=> (1 2)
(match p
((point (x 1 x)) x))
=> 1
(defstruct person (name age))
(defvar foo (make-person :name "foo" :age 30))
(match foo
((person name age) (list name age)))
=> ("foo" 30)
You can also use MAKE-INSTANCE style pattern syntax like:
(match foo
((person :name name :age age) (list name age)))
=> ("foo" 30)
This is equal to the example above except this implicitly resolves the
slot names using the Metaobject Protocol. In this case, you have to
make sure the slot names can be determined uniquely during the
compilation. Otherwise, you will get a compiler error.
#### STRUCTURE
Matches any structure value, and its slot values.
Syntax:
structure-constructor-pattern ::= (structure CONC-NAME slot*)
| (CONC-NAME slot*)
slot ::= SLOT-NAME
| (SLOT-NAME PATTERN*)
As in the CLASS constructor-pattern, STRUCTURE can be
omitted. CONC-NAME is a prefix string of a predicate (CONC-NAME +
"p") and accessors (CONC-NAME + SLOT-NAME). For example, if we have
the following defstruct,
(defstruct person name age)
the structure constructor-pattern (person- name age) is valid because
PERSON-P, PERSON-NAME and PERSON-AGE are available here. Technically,
we don’t need an actual structure definition. If we have the following
code, for instance,
(defun point-p (p) (consp p))
(defun point-x (p) (car p))
(defun point-y (p) (cdr p))
the pattern matching below is valid.
(match (cons 1 2)
((point- x y) (list x y)))
=> (1 2)
Examples:
(defstruct (person (:conc-name :p-)
(:predicate p-p))
name age)
(match (make-person :name "foo" :age 30)
((p- name age) (list name age)))
=> ("foo" 30)
As in the class constructor-pattern, you can also use MAKE-INSTANCE
style pattern syntax like:
(match (cons 1 2)
((point- :x x :y y) (list x y)))
=> (1 2)
### Derived-Pattern
A derived-pattern is a pattern that is defined with DEFPATTERN. There
are some builtin derived patterns as below:
#### LIST
Expansion of LIST derived patterns:
(list a b c) => (cons a (cons b (cons c nil)))
#### LIST*
Expansion of LIST* derived patterns:
(list* a b c) => (cons a (cons b c))
#### SATISFIES
Expansion of SATISFIES derived patterns:
(satisfies f) => (guard it (f it))
#### EQ, EQL, EQUAL, EQUALP
Expansion of EQ, EQL, EQUAL, EQUALP derived patterns:
(eq ’foo) => (guard it (eq it ’foo))
(eql 123) => (guard it (eql it 123))
(equal ’(1 2)) => (guard it (equal it ’(1 2)))
(equalp "foo") => (guard it (equalp it "foo"))
#### TYPE
Expansion of TYPE derived patterns:
(TYPE type) => (guard it (typep it ’type))
Quasiquotation
————–
You may want to use a quasiquote in a pattern specifier like:
(match ’(1 2 3 4)
(‘(1 ,x ,@y) (list x y)))
To do so, you need to use a specific quasiquote reader, for example
[fare-quasiquote](http://cliki.net/fare-quasiquote) , loading
fare-quasiquote-optima system, because there is no standard expanded
form for quasiquote expressions.
Define Constructor Patterns
—————————
You can define your own constructor patterns by using the
‘OPTIMA.CORE‘ package. First, define a data structure for the
constructor pattern.
(defstruct (my-cons-pattern (:include constructor-pattern)
(:constructor make-cons-pattern (car-pattern cdr-pattern
&aux (subpatterns (list car-pattern
cdr-pattern))))))
Note that you must keep ‘SUBPATTERNS‘ of the constructor pattern in
sync so that optima can take care of them.
Second, specify a condition for when the destructor of two constructor
patterns can be shared. This makes it possible to perform some
optimizations.
(defmethod constructor-pattern-destructor-sharable-p ((x my-cons-pattern) (y my-cons-pattern))
t)
Third, define a destructor generator for the constructor pattern. The
destructor generator will make a destructor that specifies how to
check the the data (‘PREDICATE-FORM‘) and how to access the
data (‘ACCESSOR-FORMS‘).
(defmethod constructor-pattern-make-destructor ((pattern my-cons-pattern) var)
(make-destructor :predicate-form ‘(consp ,var)
:accessor-forms (list ‘(car ,var) ‘(cdr ,var))))
Finally, define a parser and an unparser for the constructor pattern.
(defmethod parse-constructor-pattern ((name (eql ’my-cons)) &rest args)
(apply #’make-my-cons-pattern (mapcar #’parse-pattern args)))
(defmethod unparse-pattern ((pattern my-cons-pattern))
‘(cons ,(unparse-pattern (my-cons-pattern-car-pattern pattern))
,(unparse-pattern (my-cons-pattern-cdr-pattern pattern))))
See the source code for more detail.
1.0
alexandria
(system).
closer-mop
(system).
src
(module).
Modules are listed depth-first from the system components tree.
optima/src
optima
(system).
packages.lisp
(file).
util.lisp
(file).
runtime.lisp
(file).
pattern.lisp
(file).
fail.lisp
(file).
compiler.lisp
(file).
match.lisp
(file).
extra.lisp
(file).
Files are sorted by type and then listed depth-first from the systems components trees.
optima/optima.asd
optima/src/packages.lisp
optima/src/util.lisp
optima/src/runtime.lisp
optima/src/pattern.lisp
optima/src/fail.lisp
optima/src/compiler.lisp
optima/src/match.lisp
optima/src/extra.lisp
optima/src/util.lisp
packages.lisp
(file).
src
(module).
group
(function).
once-only*
(macro).
self-evaluating-object-p
(function).
set-equal
(function).
span
(function).
optima/src/runtime.lisp
util.lisp
(file).
src
(module).
%assoc
(function).
%equal
(function).
%equals
(macro).
%get-property
(function).
%svref
(function).
optima/src/pattern.lisp
runtime.lisp
(file).
src
(module).
and-pattern
(structure).
and-pattern-subpatterns
(function).
(setf and-pattern-subpatterns)
(function).
assoc-pattern
(structure).
assoc-pattern-item
(reader).
(setf assoc-pattern-item)
(writer).
assoc-pattern-key
(reader).
(setf assoc-pattern-key)
(writer).
assoc-pattern-test
(reader).
(setf assoc-pattern-test)
(writer).
assoc-pattern-value-pattern
(function).
check-patterns
(function).
class-pattern
(structure).
class-pattern-class-name
(reader).
(setf class-pattern-class-name)
(writer).
class-pattern-slot-names
(reader).
(setf class-pattern-slot-names)
(writer).
class-pattern-subpatterns
(function).
(setf class-pattern-subpatterns)
(function).
complex-pattern
(structure).
complex-pattern-subpatterns
(reader).
(setf complex-pattern-subpatterns)
(writer).
cons-pattern
(structure).
cons-pattern-car-pattern
(function).
cons-pattern-cdr-pattern
(function).
constant-pattern
(structure).
constant-pattern-value
(reader).
(setf constant-pattern-value)
(writer).
constructor-pattern
(structure).
constructor-pattern-arity
(function).
constructor-pattern-destructor-sharable-p
(generic function).
constructor-pattern-make-destructor
(generic function).
constructor-pattern-subpatterns
(function).
(setf constructor-pattern-subpatterns)
(function).
defpattern
(macro).
destructor
(structure).
destructor-accessor-forms
(reader).
(setf destructor-accessor-forms)
(writer).
guard-pattern
(structure).
guard-pattern-subpattern
(function).
guard-pattern-test-form
(reader).
(setf guard-pattern-test-form)
(writer).
lift-guard-patterns
(function).
make-and-pattern
(function).
make-assoc-pattern
(function).
make-class-pattern
(function).
make-cons-pattern
(function).
make-constant-pattern
(function).
make-destructor
(function).
make-guard-pattern
(function).
make-not-pattern
(function).
make-or-pattern
(function).
make-place-pattern
(function).
make-property-pattern
(function).
make-simple-vector-pattern
(function).
make-structure-pattern
(function).
make-variable-pattern
(function).
make-vector-pattern
(function).
not-pattern
(structure).
not-pattern-subpattern
(function).
or-pattern
(structure).
or-pattern-subpatterns
(function).
(setf or-pattern-subpatterns)
(function).
parse-constructor-pattern
(generic function).
parse-pattern
(function).
pattern-expand
(function).
pattern-expand-1
(function).
pattern-expand-all
(function).
pattern-expand-function
(function).
(setf pattern-expand-function)
(function).
pattern-variables
(function).
place-pattern
(structure).
place-pattern-included-p
(function).
place-pattern-name
(reader).
(setf place-pattern-name)
(writer).
print-object
(method).
property-pattern
(structure).
property-pattern-item
(reader).
(setf property-pattern-item)
(writer).
property-pattern-value-pattern
(function).
simple-vector-pattern
(structure).
simple-vector-pattern-subpatterns
(function).
(setf simple-vector-pattern-subpatterns)
(function).
structure-pattern
(structure).
structure-pattern-conc-name
(reader).
(setf structure-pattern-conc-name)
(writer).
structure-pattern-slot-names
(reader).
(setf structure-pattern-slot-names)
(writer).
structure-pattern-subpatterns
(function).
(setf structure-pattern-subpatterns)
(function).
unparse-pattern
(generic function).
variable-pattern
(structure).
variable-pattern-name
(reader).
(setf variable-pattern-name)
(writer).
vector-pattern
(structure).
vector-pattern-subpatterns
(function).
(setf vector-pattern-subpatterns)
(function).
%make-class-pattern
(function).
%make-structure-pattern
(function).
%make-variable-pattern
(function).
and-pattern-p
(function).
assoc-pattern-p
(function).
assoc-pattern-subpatterns
(function).
(setf assoc-pattern-subpatterns)
(function).
class-pattern-p
(function).
complex-pattern-p
(function).
cons-pattern-p
(function).
cons-pattern-subpatterns
(function).
(setf cons-pattern-subpatterns)
(function).
constant-pattern-p
(function).
constructor-pattern-p
(function).
copy-and-pattern
(function).
copy-assoc-pattern
(function).
copy-class-pattern
(function).
copy-complex-pattern
(function).
copy-cons-pattern
(function).
copy-constant-pattern
(function).
copy-constructor-pattern
(function).
copy-destructor
(function).
copy-guard-pattern
(function).
copy-not-pattern
(function).
copy-or-pattern
(function).
copy-pattern
(function).
copy-place-pattern
(function).
copy-property-pattern
(function).
copy-simple-vector-pattern
(function).
copy-structure-pattern
(function).
copy-variable-pattern
(function).
copy-vector-pattern
(function).
destructor-bindings
(reader).
(setf destructor-bindings)
(writer).
destructor-p
(function).
destructor-predicate-form
(reader).
(setf destructor-predicate-form)
(writer).
guard-pattern-p
(function).
guard-pattern-subpatterns
(function).
(setf guard-pattern-subpatterns)
(function).
lift-guard-patterns-1
(function).
lift-guard-patterns-2
(function).
make-complex-pattern
(function).
make-constructor-pattern
(function).
make-pattern
(function).
not-pattern-p
(function).
not-pattern-subpatterns
(function).
(setf not-pattern-subpatterns)
(function).
or-pattern-p
(function).
parse-class-pattern
(function).
parse-structure-pattern
(function).
pattern
(structure).
pattern-p
(function).
place-pattern-p
(function).
property-pattern-p
(function).
property-pattern-subpatterns
(function).
(setf property-pattern-subpatterns)
(function).
simple-vector-pattern-p
(function).
structure-pattern-p
(function).
variable-pattern-p
(function).
vector-pattern-p
(function).
optima/src/fail.lisp
pattern.lisp
(file).
src
(module).
fail
(macro).
optima/src/compiler.lisp
fail.lisp
(file).
src
(module).
%compile-match
(function).
%match
(macro).
*debug-compiler*
(special variable).
compile-clause-body
(function).
compile-match
(function).
compile-match-1
(function).
compile-match-constant-group
(function).
compile-match-constructor-group
(function).
compile-match-empty-group
(function).
compile-match-fail
(function).
compile-match-group
(function).
compile-match-groups
(function).
compile-match-not-group
(function).
compile-match-or-group
(function).
compile-match-place-group
(function).
compile-match-variable-group
(function).
compile-multiple-value-match
(function).
group-match-clauses
(function).
preprocess-match-clause
(function).
preprocess-match-clauses
(function).
optima/src/match.lisp
compiler.lisp
(file).
src
(module).
cmatch
(macro).
ematch
(macro).
match
(macro).
match-error
(condition).
match-error-patterns
(reader method).
match-error-values
(reader method).
multiple-value-cmatch
(macro).
multiple-value-ematch
(macro).
multiple-value-match
(macro).
optima/src/extra.lisp
match.lisp
(file).
src
(module).
if-match
(macro).
lambda-cmatch
(macro).
lambda-cmatch1
(macro).
lambda-ematch
(macro).
lambda-ematch1
(macro).
lambda-match
(macro).
lambda-match1
(macro).
let-match
(macro).
let-match*
(macro).
let-match1
(macro).
unless-match
(macro).
when-match
(macro).
Packages are listed by definition order.
optima
common-lisp
.
optima.core
.
cmatch
(macro).
defpattern
(macro).
ematch
(macro).
fail
(macro).
match
(macro).
match-error
(condition).
match-error-patterns
(generic reader).
match-error-values
(generic reader).
multiple-value-cmatch
(macro).
multiple-value-ematch
(macro).
multiple-value-match
(macro).
%compile-match
(function).
%fail
(symbol macro).
%if
(macro).
%make-class-pattern
(function).
%make-structure-pattern
(function).
%make-variable-pattern
(function).
%match
(macro).
%or
(macro).
*debug-compiler*
(special variable).
accessor-forms
(slot).
and-pattern-p
(function).
assoc-pattern-p
(function).
assoc-pattern-subpatterns
(function).
(setf assoc-pattern-subpatterns)
(function).
bindings
(slot).
class-pattern-p
(function).
cmatch*
(macro).
compile-clause-body
(function).
compile-match
(function).
compile-match-1
(function).
compile-match-constant-group
(function).
compile-match-constructor-group
(function).
compile-match-empty-group
(function).
compile-match-fail
(function).
compile-match-group
(function).
compile-match-groups
(function).
compile-match-not-group
(function).
compile-match-or-group
(function).
compile-match-place-group
(function).
compile-match-variable-group
(function).
compile-multiple-value-match
(function).
complex-pattern-p
(function).
conc-name
(slot).
cons-pattern-p
(function).
cons-pattern-subpatterns
(function).
(setf cons-pattern-subpatterns)
(function).
constant-pattern-p
(function).
constructor-pattern-p
(function).
copy-and-pattern
(function).
copy-assoc-pattern
(function).
copy-class-pattern
(function).
copy-complex-pattern
(function).
copy-cons-pattern
(function).
copy-constant-pattern
(function).
copy-constructor-pattern
(function).
copy-destructor
(function).
copy-guard-pattern
(function).
copy-not-pattern
(function).
copy-or-pattern
(function).
copy-pattern
(function).
copy-place-pattern
(function).
copy-property-pattern
(function).
copy-simple-vector-pattern
(function).
copy-structure-pattern
(function).
copy-variable-pattern
(function).
copy-vector-pattern
(function).
destructor-bindings
(reader).
(setf destructor-bindings)
(writer).
destructor-p
(function).
destructor-predicate-form
(reader).
(setf destructor-predicate-form)
(writer).
ematch*
(macro).
group
(function).
group-match-clauses
(function).
guard-pattern-p
(function).
guard-pattern-subpatterns
(function).
(setf guard-pattern-subpatterns)
(function).
item
(slot).
item
(slot).
key
(slot).
lift-guard-patterns-1
(function).
lift-guard-patterns-2
(function).
make-complex-pattern
(function).
make-constructor-pattern
(function).
make-pattern
(function).
match*
(macro).
name
(slot).
name
(slot).
not-pattern-p
(function).
not-pattern-subpatterns
(function).
(setf not-pattern-subpatterns)
(function).
once-only*
(macro).
or-pattern-p
(function).
parse-class-pattern
(function).
parse-structure-pattern
(function).
pattern
(structure).
pattern-p
(function).
place-pattern-p
(function).
predicate-form
(slot).
preprocess-match-clause
(function).
preprocess-match-clauses
(function).
property-pattern-p
(function).
property-pattern-subpatterns
(function).
(setf property-pattern-subpatterns)
(function).
self-evaluating-object-p
(function).
set-equal
(function).
simple-vector-pattern-p
(function).
slot-names
(slot).
slot-names
(slot).
span
(function).
structure-pattern-p
(function).
test
(slot).
test-form
(slot).
value
(slot).
variable-pattern-p
(function).
vector-pattern-p
(function).
optima.core
common-lisp
.
%assoc
(function).
%equal
(function).
%equals
(macro).
%get-property
(function).
%svref
(function).
and-pattern
(structure).
and-pattern-subpatterns
(function).
(setf and-pattern-subpatterns)
(function).
assoc-pattern
(structure).
assoc-pattern-item
(reader).
(setf assoc-pattern-item)
(writer).
assoc-pattern-key
(reader).
(setf assoc-pattern-key)
(writer).
assoc-pattern-test
(reader).
(setf assoc-pattern-test)
(writer).
assoc-pattern-value-pattern
(function).
check-patterns
(function).
class-pattern
(structure).
class-pattern-class-name
(reader).
(setf class-pattern-class-name)
(writer).
class-pattern-slot-names
(reader).
(setf class-pattern-slot-names)
(writer).
class-pattern-subpatterns
(function).
(setf class-pattern-subpatterns)
(function).
complex-pattern
(structure).
complex-pattern-subpatterns
(reader).
(setf complex-pattern-subpatterns)
(writer).
cons-pattern
(structure).
cons-pattern-car-pattern
(function).
cons-pattern-cdr-pattern
(function).
constant-pattern
(structure).
constant-pattern-value
(reader).
(setf constant-pattern-value)
(writer).
constructor-pattern
(structure).
constructor-pattern-arity
(function).
constructor-pattern-destructor-sharable-p
(generic function).
constructor-pattern-make-destructor
(generic function).
constructor-pattern-subpatterns
(function).
(setf constructor-pattern-subpatterns)
(function).
destructor
(structure).
destructor-accessor-forms
(reader).
(setf destructor-accessor-forms)
(writer).
guard-pattern
(structure).
guard-pattern-subpattern
(function).
guard-pattern-test-form
(reader).
(setf guard-pattern-test-form)
(writer).
lift-guard-patterns
(function).
make-and-pattern
(function).
make-assoc-pattern
(function).
make-class-pattern
(function).
make-cons-pattern
(function).
make-constant-pattern
(function).
make-destructor
(function).
make-guard-pattern
(function).
make-not-pattern
(function).
make-or-pattern
(function).
make-place-pattern
(function).
make-property-pattern
(function).
make-simple-vector-pattern
(function).
make-structure-pattern
(function).
make-variable-pattern
(function).
make-vector-pattern
(function).
not-pattern
(structure).
not-pattern-subpattern
(function).
or-pattern
(structure).
or-pattern-subpatterns
(function).
(setf or-pattern-subpatterns)
(function).
parse-constructor-pattern
(generic function).
parse-pattern
(function).
pattern-expand
(function).
pattern-expand-1
(function).
pattern-expand-all
(function).
pattern-expand-function
(function).
(setf pattern-expand-function)
(function).
pattern-variables
(function).
place-pattern
(structure).
place-pattern-included-p
(function).
place-pattern-name
(reader).
(setf place-pattern-name)
(writer).
property-pattern
(structure).
property-pattern-item
(reader).
(setf property-pattern-item)
(writer).
property-pattern-value-pattern
(function).
simple-vector-pattern
(structure).
simple-vector-pattern-subpatterns
(function).
(setf simple-vector-pattern-subpatterns)
(function).
structure-pattern
(structure).
structure-pattern-conc-name
(reader).
(setf structure-pattern-conc-name)
(writer).
structure-pattern-slot-names
(reader).
(setf structure-pattern-slot-names)
(writer).
structure-pattern-subpatterns
(function).
(setf structure-pattern-subpatterns)
(function).
unparse-pattern
(generic function).
variable-pattern
(structure).
variable-pattern-name
(reader).
(setf variable-pattern-name)
(writer).
vector-pattern
(structure).
vector-pattern-subpatterns
(function).
(setf vector-pattern-subpatterns)
(function).
optima.extra
### [Pattern] alist
Syntax:
(alist (KEY . PATTERN)*)
Expansion:
(alist (k . p)*) => (and (assoc k p)*)
Examples:
(match ’((1 . :one) (2 . :two) (3 . :three))
((alist (1 . x) (3 . y)) (list x y)))
=> (:ONE :THREE)
### [Pattern] plist
Syntax:
(plist {KEY PATTERN}*)
Expansion:
(plist {k p}*) => (and (property k p)*)
Examples:
(match ’(:name "John" :age 23)
((plist :name "John" :age age) age))
=> 23
common-lisp
.
optima
.
if-match
(macro).
lambda-cmatch
(macro).
lambda-cmatch1
(macro).
lambda-ematch
(macro).
lambda-ematch1
(macro).
lambda-match
(macro).
lambda-match1
(macro).
let-match
(macro).
let-match*
(macro).
let-match1
(macro).
unless-match
(macro).
when-match
(macro).
Definitions are sorted by export status, category, package, and then by lexicographic order.
Equality macro for comparing pattern constants. This specializes
the comparison form to some specific form as follows:
(equals x nil) => (null x)
(equals x ’foo) => (eq x ’foo)
(equals x 123) => (eql x 123)
(equals x ’(a b)) => (%equals x ’(a b))
Same as MATCH, except a continuable MATCH-ERROR will be raised if none of the clauses match.
Defines a derived pattern specifier named NAME. This is analogous
to DEFTYPE.
Examples:
;; Defines a LIST pattern.
(defpattern list (&rest args)
(when args
‘(cons ,(car args) (list ,@(cdr args)))))
Same as MATCH, except MATCH-ERROR will be raised if not matched.
Causes the latest pattern matching to fail. After this failure, matching continues at the next pattern.
Equivalent to (match ARG (PATTERN THEN) (otherwise ELSE)).
Equivalent to (lambda (arg) (cmatch arg CLAUSES...)).
Equivalent to (lambda-cmatch (PATTERN BODY...)).
Equivalent to (lambda (arg) (ematch arg CLAUSES...)).
Equivalent to (lambda-ematch (PATTERN BODY...)).
Equivalent to (lambda (arg) (match arg CLAUSES...)).
Equivalent to (lambda-match (PATTERN BODY...)).
Similar to LET, except not only a variable but also a pattern can be used in BINDINGS.
Similar to LET-MATCH but matches sequentially.
Equivalent to (let-match ((PATTERN ARG)) BODY...).
Matches ARG with CLAUSES. CLAUSES is a list of the form of (PATTERN
. BODY) where PATTERN is a pattern specifier and BODY is an implicit
progn. If ARG matches some PATTERN, ‘match‘ then evaluates
the corresponding BODY and returns the evaluated value. If no pattern matches,
then returns NIL.
Evaluating a form (FAIL) in the clause body causes the latest pattern
matching to fail. For example,
(match 1
(x (if (eql x 1)
(fail)
x))
(_ ’ok))
returns OK, because the form (FAIL) in the first clause is
evaluated.
If BODY starts with the symbols WHEN or UNLESS, then the next form
will be used to introduce (FAIL). That is,
(match list ((list x) when (oddp x) x))
(match list ((list x) unless (evenp x) x))
will be translated to
(match list ((list x) (if (oddp x) x (fail))))
(match list ((list x) (if (evenp x) (fail) x)))
Examples:
(match 1 (1 1))
=> 1
(match 1 (2 2))
=> 2
(match 1 (x x))
=> 1
(match (list 1 2 3)
(list x y z) (+ x y z))
=> 6
Same as MULTIPLE-VALUE-MATCH, except a continuable MATCH-ERROR will be raised if none of the clauses match.
Same as MULTIPLE-VALUE-MATCH, except MATCH-ERROR will be raised if not matched.
Matches the multiple values of VALUES-FORM with CLAUSES. Unlike MATCH, CLAUSES have to have the form of (PATTERNS . BODY), where PATTERNS is a list of patterns. The number of values that will be used to match is determined by the maximum arity of PATTERNS among CLAUSES.
Examples:
(multiple-value-match (values 1 2)
((2) 1)
((1 y) y))
=> 2
Equivalent to (match ARG (PATTERN) (otherwise BODY...)).
Equivalent to (match ARG (PATTERN BODY...)).
Safe ASSOC.
Equality function for comparing pattern constants.
Safe GETF.
Safe SVREF.
item
.
key
.
test
.
Check if PATTERNS are valid. Otherwise, an error will be raised.
Returns the set of variables in PATTERN. If PATTERN is not linear, an error will be raised.
name
.
item
.
name
.
structure-pattern
) (y structure-pattern
)) ¶class-pattern
) (y class-pattern
)) ¶simple-vector-pattern
) (y simple-vector-pattern
)) ¶vector-pattern
) (y vector-pattern
)) ¶property-pattern
) (y property-pattern
)) ¶assoc-pattern
) (y assoc-pattern
)) ¶cons-pattern
) (y cons-pattern
)) ¶structure-pattern
) var) ¶class-pattern
) var) ¶simple-vector-pattern
) var) ¶vector-pattern
) var) ¶property-pattern
) var) ¶assoc-pattern
) var) ¶cons-pattern
) var) ¶match-error
)) ¶match-error
)) ¶(eql structure)
) &rest args) ¶(eql class)
) &rest args) ¶(eql simple-vector)
) &rest args) ¶(eql vector)
) &rest args) ¶(eql optima:property)
) &rest args) ¶(eql assoc)
) &rest args) ¶(eql cons)
) &rest args) ¶structure-pattern
)) ¶class-pattern
)) ¶simple-vector-pattern
)) ¶vector-pattern
)) ¶property-pattern
)) ¶assoc-pattern
)) ¶cons-pattern
)) ¶and-pattern
)) ¶or-pattern
)) ¶not-pattern
)) ¶guard-pattern
)) ¶constant-pattern
)) ¶place-pattern
)) ¶variable-pattern
)) ¶Similar to IF except %IF also allows to call (FAIL) in THEN branch to jump to ELSE branch.
Compiler cushion macro. This is useful for seeing and debugging the process of pattern matching compiler.
Causes the latest pattern matching to fail. After this failure, matching continues at the next pattern.
Lifts GUARD patterns in PATTERN so that the guards can see
any variables in PATTERN. The transform looks like:
(list x (guard y (equal x y)))
=> (guard (list x y) (equal x y))
Multiple guards will be connected with conjunction in order of
occurence like:
(list (guard x (consp x)) (guard y (eq y (car x)))) => (guard (list x (guard y (eq y (car x)))) (consp x)) => (guard (guard (list x y) (eq y (car x))) (consp x)) => (guard (list x y) (and (consp x) (eq y (car x))))
Lifts OR patterns that include guards like:
(list 3 (or 1 (guard x (evenp x))))
=> (or (list 3 1) (list 3 (guard x (evenp x))))
=> (or (list 3 1) (guard (list 3 x) (evenp x)))
structure-object
.
Jump to: | %
(
A C D E F G I L M N O P S U V W |
---|
Jump to: | %
(
A C D E F G I L M N O P S U V W |
---|
Jump to: | %
*
A B C I K N P S T V |
---|
Jump to: | %
*
A B C I K N P S T V |
---|
Jump to: | A C D E F G M N O P R S U V |
---|
Jump to: | A C D E F G M N O P R S U V |
---|