Common Lisp Package: OPTIMA

README:

optima - Optimized Pattern Matching Library

optima is a very fast pattern matching library which uses optimizing techniques widely used in a functional programming world. See the following references for more detail:

Pattern Language

A pattern specifier, or a pattern for short unless ambiguous, is an expression that describes how a value matches the pattern. 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  
                   | 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 bind the value to the variable. _ and otherwise is a special variable-pattern (a.k.a wildcard-pattern) which matches any value but doesn'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 like variable-patterns but bind the value with 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 also tests whether TEST-FORM satisfies 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. There is a restriction that every pattern of sub-PATTERNs must have same set of variables.

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 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 not a value itself but a structure of the value. 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 are 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 Meta Object Protocol. In this case, you have to make sure the slot names can be determined uniquely during the compilation. Otherwise, you will get a compilation 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 well as 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 a structure defined. 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) 

Same as 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 dervied 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) => (when (typep * 'type)) 

[Package] optima

[Macro] match

match arg &body clauses 

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 is matched with some PATTERN, then evaluates corresponding BODY and returns the evaluated value. Otherwise, returns NIL.

Evaluating a form (FAIL) in the clause body causes the latest pattern matching be failed. 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 

[Macro] multiple-value-match

multiple-value-match values-form &body clauses 

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 

[Macro] ematch

ematch arg &body clauses 

Same as MATCH, except MATCH-ERROR will be raised if not matched.

[Macro] multiple-value-ematch

multiple-value-ematch values-form &body clauses 

Same as MULTIPLE-VALUE-MATCH, except MATCH-ERROR will be raised if not matched.

[Macro] cmatch

cmatch arg &body clauses 

Same as MATCH, except continuable MATCH-ERROR will be raised if not matched.

[Macro] multiple-value-cmatch

multiple-value-cmatch values-form &body clauses 

Same as MULTIPLE-VALUE-MATCH, except continuable MATCH-ERROR will be raised if not matched.

[Macro] fail

fail 

Causes the latest pattern matching be failed and continue to do the rest of pattern matching.

[Class] match-error

[Type] match-error

match-error 

[Function] match-error-values

match-error-values condition 

[Function] match-error-patterns

match-error-patterns condition 

[Macro] defpattern

defpattern name lambda-list &body body 

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

[Package] 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 

[Macro] if-match

if-match pattern arg &body (then &optional else) 

Equivalent to (match ARG (PATTERN THEN) (otherwise ELSE)).

[Macro] when-match

when-match pattern arg &body body 

Equivalent to (match ARG (PATTERN BODY...)).

[Macro] unless-match

unless-match pattern arg &body body 

Equivalent to (match ARG (PATTERN) (otherwise BODY...)).

[Macro] let-match

let-match bindings &body body 

Similar to LET, except not only a variable but also a pattern can be used in BINDINGS.

[Macro] let-match*

let-match* bindings &body body 

Similar to LET-MATCH but matches sequentially.

[Macro] let-match1

let-match1 pattern arg &body body 

Equivalent to (let-match ((PATTERN ARG)) BODY...).

Authors

  • Tomohiro Matsuyama

License

LLGPL

optima.ppcre - CL-PPCRE support for optima

[Package] optima.ppcre

[Pattern] ppcre

Syntax:

(ppcre REGEXP PATTERN*) 

Matches REGEXP against the target string. Sub-PATTERNs will be used to match the matched groups, if REGEXP matched.

Examples:

(match "2012-11-04"  
  ((ppcre "^\\d{4}-\\d{2}-\\d{2}$" year month day)  
   (list year month day)))  
=> ("2012" "11" "04") 

Authors

  • Tomohiro Matsuyama

License

LLGPL

FUNCTION

Private

%ASSOC (ITEM ALIST &KEY (TEST #'EQL))

Safe ASSOC.

%EQUAL (A B)

Equality function for comparing patten constants.

%GET-PROPERTY (ITEM PLIST)

Safe GETF.

%SVREF (SIMPLE-VECTOR INDEX)

Safe SVREF.

AND-PATTERN-SUBPATTERNS (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

ASSOC-PATTERN-ITEM (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

ASSOC-PATTERN-KEY (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

ASSOC-PATTERN-SUBPATTERNS (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

ASSOC-PATTERN-TEST (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

CHECK-PATTERNS (PATTERNS)

Check if PATTERNS are valid. Otherwise, an error will be raised.

CLASS-PATTERN-CLASS-NAME (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

CLASS-PATTERN-SLOT-NAMES (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

CLASS-PATTERN-SUBPATTERNS (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

COMPLEX-PATTERN-SUBPATTERNS (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

CONS-PATTERN-SUBPATTERNS (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

CONSTANT-PATTERN-VALUE (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

CONSTRUCTOR-PATTERN-SUBPATTERNS (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

ENSURE-CAR (THING)

If THING is a CONS, its CAR is returned. Otherwise THING is returned.

ENSURE-LIST (LIST)

If LIST is a list, it is returned. Otherwise returns the list designated by LIST.

GUARD-PATTERN-SUBPATTERNS (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

GUARD-PATTERN-TEST-FORM (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

LIFT-GUARD-PATTERNS-1 (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))))

LIFT-GUARD-PATTERNS-2 (PATTERN)

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

MAKE-GENSYM-LIST (LENGTH &OPTIONAL (X G))

Returns a list of LENGTH gensyms, each generated as if with a call to MAKE-GENSYM, using the second (optional, defaulting to "G") argument.

MAKE-KEYWORD (NAME)

Interns the string designated by NAME in the KEYWORD package.

MAPPEND (FUNCTION &REST LISTS)

Applies FUNCTION to respective element(s) of each LIST, appending all the all the result list to a single list. FUNCTION must return a list.

NOT-PATTERN-SUBPATTERNS (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

OR-PATTERN-SUBPATTERNS (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

PATTERN-VARIABLES (PATTERN)

Returns the set of variables in PATTERN. If PATTERN is not linear, an error will be raised.

PLACE-PATTERN-NAME (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

PLIST-ALIST (PLIST)

Returns an association list containing the same keys and values as the property list PLIST in the same order.

PROPERTY-PATTERN-ITEM (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

PROPERTY-PATTERN-SUBPATTERNS (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

REQUIRED-ARGUMENT (&OPTIONAL NAME)

Signals an error for a missing argument of NAME. Intended for use as an initialization form for structure and class-slots, and a default value for required keyword arguments.

SIMPLE-VECTOR-PATTERN-SUBPATTERNS (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

STRUCTURE-PATTERN-CONC-NAME (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

STRUCTURE-PATTERN-SLOT-NAMES (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

STRUCTURE-PATTERN-SUBPATTERNS (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

SYMBOLICATE (&REST THINGS)

Concatenate together the names of some strings and symbols, producing a symbol in the current package.

VARIABLE-PATTERN-NAME (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

VECTOR-PATTERN-SUBPATTERNS (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

Undocumented

%MAKE-CLASS-PATTERN (&KEY ((SUBPATTERNS DUM566) NIL) ((CLASS-NAME DUM567) NIL) ((SLOT-NAMES DUM568) NIL))

%MAKE-STRUCTURE-PATTERN (&KEY ((SUBPATTERNS DUM679) NIL) ((CONC-NAME DUM680) NIL) ((SLOT-NAMES DUM681) NIL))

%MAKE-VARIABLE-PATTERN (NAME)

AND-PATTERN-P (OBJECT)

SETFAND-PATTERN-SUBPATTERNS (NEW-VALUE INSTANCE)

SETFASSOC-PATTERN-ITEM (NEW-VALUE INSTANCE)

SETFASSOC-PATTERN-KEY (NEW-VALUE INSTANCE)

ASSOC-PATTERN-P (OBJECT)

SETFASSOC-PATTERN-SUBPATTERNS (NEW-VALUE INSTANCE)

SETFASSOC-PATTERN-TEST (NEW-VALUE INSTANCE)

ASSOC-PATTERN-VALUE-PATTERN (PATTERN)

SETFCLASS-PATTERN-CLASS-NAME (NEW-VALUE INSTANCE)

CLASS-PATTERN-P (OBJECT)

SETFCLASS-PATTERN-SLOT-NAMES (NEW-VALUE INSTANCE)

SETFCLASS-PATTERN-SUBPATTERNS (NEW-VALUE INSTANCE)

COMPILE-CLAUSE-BODY (BODY)

COMPILE-MATCH (VARS CLAUSES ELSE)

COMPILE-MATCH-1 (FORM CLAUSES ELSE)

COMPILE-MATCH-CONSTANT-GROUP (VARS CLAUSES ELSE)

COMPILE-MATCH-CONSTRUCTOR-GROUP (VARS CLAUSES ELSE)

COMPILE-MATCH-EMPTY-GROUP (CLAUSES ELSE)

COMPILE-MATCH-FAIL (FORM ELSE)

COMPILE-MATCH-GROUP (VARS GROUP ELSE)

COMPILE-MATCH-GROUPS (VARS GROUPS ELSE)

COMPILE-MATCH-NOT-GROUP (VARS CLAUSES ELSE)

COMPILE-MATCH-OR-GROUP (VARS CLAUSES ELSE)

COMPILE-MATCH-PLACE-GROUP (VARS CLAUSES ELSE)

COMPILE-MATCH-VARIABLE-GROUP (VARS CLAUSES ELSE)

COMPILE-MULTIPLE-VALUE-MATCH (VALUES-FORM CLAUSES ELSE)

COMPLEX-PATTERN-P (OBJECT)

SETFCOMPLEX-PATTERN-SUBPATTERNS (NEW-VALUE INSTANCE)

CONS-PATTERN-CAR-PATTERN (PATTERN)

CONS-PATTERN-CDR-PATTERN (PATTERN)

CONS-PATTERN-P (OBJECT)

SETFCONS-PATTERN-SUBPATTERNS (NEW-VALUE INSTANCE)

CONSTANT-PATTERN-P (OBJECT)

SETFCONSTANT-PATTERN-VALUE (NEW-VALUE INSTANCE)

CONSTRUCTOR-PATTERN-ARITY (PATTERN)

CONSTRUCTOR-PATTERN-P (OBJECT)

SETFCONSTRUCTOR-PATTERN-SUBPATTERNS (NEW-VALUE INSTANCE)

COPY-AND-PATTERN (INSTANCE)

COPY-ASSOC-PATTERN (INSTANCE)

COPY-CLASS-PATTERN (INSTANCE)

COPY-COMPLEX-PATTERN (INSTANCE)

COPY-CONS-PATTERN (INSTANCE)

COPY-CONSTANT-PATTERN (INSTANCE)

COPY-CONSTRUCTOR-PATTERN (INSTANCE)

COPY-GUARD-PATTERN (INSTANCE)

COPY-NOT-PATTERN (INSTANCE)

COPY-OR-PATTERN (INSTANCE)

COPY-PATTERN (INSTANCE)

COPY-PLACE-PATTERN (INSTANCE)

COPY-PROPERTY-PATTERN (INSTANCE)

COPY-SIMPLE-VECTOR-PATTERN (INSTANCE)

COPY-STRUCTURE-PATTERN (INSTANCE)

COPY-VARIABLE-PATTERN (INSTANCE)

COPY-VECTOR-PATTERN (INSTANCE)

GROUP (LIST &KEY (TEST #'EQL) (KEY #'IDENTITY))

GROUP-MATCH-CLAUSES (CLAUSES)

GUARD-PATTERN-P (OBJECT)

GUARD-PATTERN-SUBPATTERN (PATTERN)

SETFGUARD-PATTERN-SUBPATTERNS (NEW-VALUE INSTANCE)

SETFGUARD-PATTERN-TEST-FORM (NEW-VALUE INSTANCE)

LIFT-GUARD-PATTERNS (PATTERN)

MAKE-AND-PATTERN (&REST SUBPATTERNS)

MAKE-ASSOC-PATTERN (ITEM VALUE-PATTERN &KEY (KEY NIL) (TEST NIL) &AUX (SUBPATTERNS (LIST VALUE-PATTERN)))

MAKE-CLASS-PATTERN (CLASS-NAME &REST SLOT-SPECS)

MAKE-COMPLEX-PATTERN (&KEY ((SUBPATTERNS DUM97) NIL))

MAKE-CONS-PATTERN (CAR-PATTERN CDR-PATTERN &AUX (SUBPATTERNS (LIST CAR-PATTERN CDR-PATTERN)))

MAKE-CONSTANT-PATTERN (VALUE)

MAKE-CONSTRUCTOR-PATTERN (&KEY ((SUBPATTERNS DUM216) NIL))

MAKE-GUARD-PATTERN (SUBPATTERN TEST-FORM &AUX (SUBPATTERNS (LIST SUBPATTERN)))

MAKE-NOT-PATTERN (SUBPATTERN &AUX (SUBPATTERNS (LIST SUBPATTERN)))

MAKE-OR-PATTERN (&REST SUBPATTERNS)

MAKE-PATTERN (&KEY)

MAKE-PLACE-PATTERN (NAME)

MAKE-PROPERTY-PATTERN (ITEM VALUE-PATTERN &AUX (SUBPATTERNS (LIST VALUE-PATTERN)))

MAKE-SIMPLE-VECTOR-PATTERN (&REST SUBPATTERNS)

MAKE-STRUCTURE-PATTERN (CONC-NAME &REST SLOT-SPECS)

MAKE-VARIABLE-PATTERN (&OPTIONAL NAME)

MAKE-VECTOR-PATTERN (&REST SUBPATTERNS)

NOT-PATTERN-P (OBJECT)

NOT-PATTERN-SUBPATTERN (PATTERN)

SETFNOT-PATTERN-SUBPATTERNS (NEW-VALUE INSTANCE)

OR-PATTERN-P (OBJECT)

SETFOR-PATTERN-SUBPATTERNS (NEW-VALUE INSTANCE)

PARSE-CLASS-PATTERN (CLASS-NAME &REST SLOT-SPECS)

PARSE-PATTERN (PATTERN)

PARSE-STRUCTURE-PATTERN (CONC-NAME &REST SLOT-SPECS)

PATTERN-EXPAND (PATTERN)

PATTERN-EXPAND-1 (PATTERN)

PATTERN-EXPAND-ALL (PATTERN)

PATTERN-EXPAND-FUNCTION (NAME)

SETFPATTERN-EXPAND-FUNCTION (FUNCTION NAME)

PATTERN-P (OBJECT)

PLACE-PATTERN-INCLUDED-P (PATTERN)

SETFPLACE-PATTERN-NAME (NEW-VALUE INSTANCE)

PLACE-PATTERN-P (OBJECT)

PREPROCESS-MATCH-CLAUSE (CLAUSE)

PREPROCESS-MATCH-CLAUSES (VARS CLAUSES)

SETFPROPERTY-PATTERN-ITEM (NEW-VALUE INSTANCE)

PROPERTY-PATTERN-P (OBJECT)

SETFPROPERTY-PATTERN-SUBPATTERNS (NEW-VALUE INSTANCE)

PROPERTY-PATTERN-VALUE-PATTERN (PATTERN)

SELF-EVALUATING-OBJECT-P (OBJECT)

SET-EQUAL (SET1 SET2)

SIMPLE-VECTOR-PATTERN-P (OBJECT)

SETFSIMPLE-VECTOR-PATTERN-SUBPATTERNS (NEW-VALUE INSTANCE)

SPAN (LIST &KEY (TEST #'EQL) (KEY #'IDENTITY))

SETFSTRUCTURE-PATTERN-CONC-NAME (NEW-VALUE INSTANCE)

STRUCTURE-PATTERN-P (OBJECT)

SETFSTRUCTURE-PATTERN-SLOT-NAMES (NEW-VALUE INSTANCE)

SETFSTRUCTURE-PATTERN-SUBPATTERNS (NEW-VALUE INSTANCE)

SETFVARIABLE-PATTERN-NAME (NEW-VALUE INSTANCE)

VARIABLE-PATTERN-P (OBJECT)

VECTOR-PATTERN-P (OBJECT)

SETFVECTOR-PATTERN-SUBPATTERNS (NEW-VALUE INSTANCE)

MACRO

Public

CMATCH (ARG &BODY CLAUSES)

Same as MATCH, except continuable MATCH-ERROR will be raised if not matched.

DEFPATTERN (NAME LAMBDA-LIST &BODY BODY)

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

EMATCH (ARG &BODY CLAUSES)

Same as MATCH, except MATCH-ERROR will be raised if not matched.

FAIL

Causes the latest pattern matching be failed and continue to do the rest of pattern matching.

MATCH (ARG &BODY CLAUSES)

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 is matched with some PATTERN, then evaluates corresponding BODY and returns the evaluated value. Otherwise, returns NIL. Evaluating a form (FAIL) in the clause body causes the latest pattern matching be failed. 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

MULTIPLE-VALUE-CMATCH (VALUES-FORM &BODY CLAUSES)

Same as MULTIPLE-VALUE-MATCH, except continuable MATCH-ERROR will be raised if not matched.

MULTIPLE-VALUE-EMATCH (VALUES-FORM &BODY CLAUSES)

Same as MULTIPLE-VALUE-MATCH, except MATCH-ERROR will be raised if not matched.

MULTIPLE-VALUE-MATCH (VALUES-FORM &BODY CLAUSES)

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

Private

%IF (TEST THEN ELSE)

Similar to IF except %IF also allows to call (FAIL) in THEN branch to jump to ELSE branch.

%MATCH (VARS CLAUSES ELSE)

Compiler cushion macro. This is useful for seeing and debugging the process of pattern matching compiler.

%OR (&REST FORMS)

Similar to OR except %OR also allows to call (FAIL) in each branch to jump to its next branch.

DESTRUCTURING-CASE (KEYFORM &BODY CLAUSES)

DESTRUCTURING-CASE, -CCASE, and -ECASE are a combination of CASE and DESTRUCTURING-BIND. KEYFORM must evaluate to a CONS. Clauses are of the form: ((CASE-KEYS . DESTRUCTURING-LAMBDA-LIST) FORM*) The clause whose CASE-KEYS matches CAR of KEY, as if by CASE, CCASE, or ECASE, is selected, and FORMs are then executed with CDR of KEY is destructured and bound by the DESTRUCTURING-LAMBDA-LIST. Example: (defun dcase (x) (destructuring-case x ((:foo a b) (format nil "foo: ~S, ~S" a b)) ((:bar &key a b) (format nil "bar, ~S, ~S" a b)) (((:alt1 :alt2) a) (format nil "alt: ~S" a)) ((t &rest rest) (format nil "unknown: ~S" rest)))) (dcase (list :foo 1 2)) ; => "foo: 1, 2" (dcase (list :bar :a 1 :b 2)) ; => "bar: 1, 2" (dcase (list :alt1 1)) ; => "alt: 1" (dcase (list :alt2 2)) ; => "alt: 2" (dcase (list :quux 1 2 3)) ; => "unknown: 1, 2, 3" (defun decase (x) (destructuring-case x ((:foo a b) (format nil "foo: ~S, ~S" a b)) ((:bar &key a b) (format nil "bar, ~S, ~S" a b)) (((:alt1 :alt2) a) (format nil "alt: ~S" a)))) (decase (list :foo 1 2)) ; => "foo: 1, 2" (decase (list :bar :a 1 :b 2)) ; => "bar: 1, 2" (decase (list :alt1 1)) ; => "alt: 1" (decase (list :alt2 2)) ; => "alt: 2" (decase (list :quux 1 2 3)) ; =| error

EQUALS (VAR VALUE)

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

IF-LET (BINDINGS &BODY (THEN-FORM &OPTIONAL ELSE-FORM))

Creates new variable bindings, and conditionally executes either THEN-FORM or ELSE-FORM. ELSE-FORM defaults to NIL. BINDINGS must be either single binding of the form: (variable initial-form) or a list of bindings of the form: ((variable-1 initial-form-1) (variable-2 initial-form-2) ... (variable-n initial-form-n)) All initial-forms are executed sequentially in the specified order. Then all the variables are bound to the corresponding values. If all variables were bound to true values, the THEN-FORM is executed with the bindings in effect, otherwise the ELSE-FORM is executed with the bindings in effect.

ONCE-ONLY (SPECS &BODY FORMS)

Evaluates FORMS with symbols specified in SPECS rebound to temporary variables, ensuring that each initform is evaluated only once. Each of SPECS must either be a symbol naming the variable to be rebound, or of the form: (symbol initform) Bare symbols in SPECS are equivalent to (symbol symbol) Example: (defmacro cons1 (x) (once-only (x) `(cons ,x ,x))) (let ((y 0)) (cons1 (incf y))) => (1 . 1)

WHEN-LET (BINDINGS &BODY FORMS)

Creates new variable bindings, and conditionally executes FORMS. BINDINGS must be either single binding of the form: (variable initial-form) or a list of bindings of the form: ((variable-1 initial-form-1) (variable-2 initial-form-2) ... (variable-n initial-form-n)) All initial-forms are executed sequentially in the specified order. Then all the variables are bound to the corresponding values. If all variables were bound to true values, then FORMS are executed as an implicit PROGN.

WITH-UNIQUE-NAMES (NAMES &BODY FORMS)

Alias for WITH-GENSYMS.

Undocumented

CMATCH* (ARGS &BODY CLAUSES)

EMATCH* (ARGS &BODY CLAUSES)

MATCH* (ARGS &BODY CLAUSES)

ONCE-ONLY* (SYMBOL &BODY BODY)

GENERIC-FUNCTION

Public

Undocumented

MATCH-ERROR-PATTERNS (CONDITION)

MATCH-ERROR-VALUES (CONDITION)

Private

Undocumented

SETFCLASS-SLOTS (NEW-VALUE SLOT-CLASS)

DESTRUCTOR-EQUAL (DTOR1 DTOR2)

DESTRUCTOR-FORMS (DTOR VAR)

DESTRUCTOR-PREDICATE-FORM (DTOR VAR)

PARSE-CONSTRUCTOR-PATTERN (NAME &REST ARGS)

UNPARSE-PATTERN (PATTERN)

SLOT-ACCESSOR

Private

Undocumented

CLASS-SLOTS (CLASS)

SLOT-DEFINITION-NAME (SLOT-DEFINITION)

SETFSLOT-DEFINITION-NAME (NEW-VALUE SLOT-DEFINITION)

CLASS

Private

Undocumented

AND-PATTERN

ASSOC-PATTERN

CLASS-PATTERN

COMPLEX-PATTERN

CONS-PATTERN

CONSTANT-PATTERN

CONSTRUCTOR-PATTERN

GUARD-PATTERN

NOT-PATTERN

OR-PATTERN

PATTERN

PLACE-PATTERN

PROPERTY-PATTERN

SIMPLE-VECTOR-PATTERN

STRUCTURE-PATTERN

VARIABLE-PATTERN

VECTOR-PATTERN

CONDITION

Public

Undocumented

MATCH-ERROR