optima

API Reference

optima

Optimized Pattern Matching Library

OPTIMA.CORE

  • Function %EQUAL (a b)
    Equality function for comparing pattern constants.
  • Macro %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))
  • Function %SVREF (simple-vector index)
    Safe SVREF.
  • Function %ASSOC (item alist &key (test #'eql))
    Safe ASSOC.
  • Function %GET-PROPERTY (item plist)
    Safe GETF.
  • Struct DESTRUCTOR
    BINDINGS
    PREDICATE-FORM
    ACCESSOR-FORMS
  • Function DESTRUCTOR-ACCESSOR-FORMS (instance)
  • Function (setf DESTRUCTOR-ACCESSOR-FORMS) (value instance)
  • Function MAKE-DESTRUCTOR (&key ((bindings bindings) nil) ((predicate-form predicate-form) nil) ((accessor-forms accessor-forms) nil))
  • Struct VARIABLE-PATTERN
    NAME
  • Function VARIABLE-PATTERN-NAME (instance)
  • Function (setf VARIABLE-PATTERN-NAME) (value instance)
  • Function MAKE-VARIABLE-PATTERN (&optional name)
  • Struct PLACE-PATTERN
    NAME
  • Function PLACE-PATTERN-NAME (instance)
  • Function (setf PLACE-PATTERN-NAME) (value instance)
  • Function MAKE-PLACE-PATTERN (name)
  • Struct CONSTANT-PATTERN
    VALUE
  • Function CONSTANT-PATTERN-VALUE (instance)
  • Function (setf CONSTANT-PATTERN-VALUE) (value instance)
  • Function MAKE-CONSTANT-PATTERN (value)
  • Struct COMPLEX-PATTERN
    SUBPATTERNS
  • Function COMPLEX-PATTERN-SUBPATTERNS (instance)
  • Function (setf COMPLEX-PATTERN-SUBPATTERNS) (value instance)
  • Struct GUARD-PATTERN
    TEST-FORM
  • Function GUARD-PATTERN-TEST-FORM (instance)
  • Function (setf GUARD-PATTERN-TEST-FORM) (value instance)
  • Function MAKE-GUARD-PATTERN (subpattern test-form &aux (subpatterns (list optima::subpattern)))
  • Function GUARD-PATTERN-SUBPATTERN (pattern)
  • Struct NOT-PATTERN
    No slots.
  • Function MAKE-NOT-PATTERN (subpattern &aux (subpatterns (list optima::subpattern)))
  • Function NOT-PATTERN-SUBPATTERN (pattern)
  • Struct OR-PATTERN
    No slots.
  • Function OR-PATTERN-SUBPATTERNS (instance)
  • Function (setf OR-PATTERN-SUBPATTERNS) (value instance)
  • Function MAKE-OR-PATTERN (&rest subpatterns)
  • Struct AND-PATTERN
    No slots.
  • Function AND-PATTERN-SUBPATTERNS (instance)
  • Function (setf AND-PATTERN-SUBPATTERNS) (value instance)
  • Function MAKE-AND-PATTERN (&rest subpatterns)
  • Struct CONSTRUCTOR-PATTERN
    No slots.
  • Function CONSTRUCTOR-PATTERN-SUBPATTERNS (instance)
  • Function (setf CONSTRUCTOR-PATTERN-SUBPATTERNS) (value instance)
  • Function CONSTRUCTOR-PATTERN-ARITY (pattern)
  • Generic-Function CONSTRUCTOR-PATTERN-DESTRUCTOR-SHARABLE-P (x y)
  • Generic-Function CONSTRUCTOR-PATTERN-MAKE-DESTRUCTOR (pattern var)
  • Struct CONS-PATTERN
    No slots.
  • Function MAKE-CONS-PATTERN (car-pattern cdr-pattern &aux (subpatterns (list optima::car-pattern optima::cdr-pattern)))
  • Function CONS-PATTERN-CAR-PATTERN (pattern)
  • Function CONS-PATTERN-CDR-PATTERN (pattern)
  • Method CONSTRUCTOR-PATTERN-MAKE-DESTRUCTOR ((pattern cons-pattern) var)
  • Struct ASSOC-PATTERN
    ITEM
    KEY
    TEST
  • Function ASSOC-PATTERN-ITEM (instance)
  • Function (setf ASSOC-PATTERN-ITEM) (value instance)
  • Function ASSOC-PATTERN-KEY (instance)
  • Function (setf ASSOC-PATTERN-KEY) (value instance)
  • Function ASSOC-PATTERN-TEST (instance)
  • Function (setf ASSOC-PATTERN-TEST) (value instance)
  • Function MAKE-ASSOC-PATTERN (item value-pattern &key (key nil) (test nil) &aux (subpatterns (list optima::value-pattern)))
  • Function ASSOC-PATTERN-VALUE-PATTERN (pattern)
  • Method CONSTRUCTOR-PATTERN-DESTRUCTOR-SHARABLE-P ((x assoc-pattern) (y assoc-pattern))
  • Method CONSTRUCTOR-PATTERN-MAKE-DESTRUCTOR ((pattern assoc-pattern) var)
  • Struct PROPERTY-PATTERN
    ITEM
  • Function PROPERTY-PATTERN-ITEM (instance)
  • Function (setf PROPERTY-PATTERN-ITEM) (value instance)
  • Function MAKE-PROPERTY-PATTERN (item value-pattern &aux (subpatterns (list optima::value-pattern)))
  • Function PROPERTY-PATTERN-VALUE-PATTERN (pattern)
  • Method CONSTRUCTOR-PATTERN-DESTRUCTOR-SHARABLE-P ((x property-pattern) (y property-pattern))
  • Method CONSTRUCTOR-PATTERN-MAKE-DESTRUCTOR ((pattern property-pattern) var)
  • Struct VECTOR-PATTERN
    No slots.
  • Function VECTOR-PATTERN-SUBPATTERNS (instance)
  • Function (setf VECTOR-PATTERN-SUBPATTERNS) (value instance)
  • Function MAKE-VECTOR-PATTERN (&rest subpatterns)
  • Method CONSTRUCTOR-PATTERN-DESTRUCTOR-SHARABLE-P ((x vector-pattern) (y vector-pattern))
  • Method CONSTRUCTOR-PATTERN-MAKE-DESTRUCTOR ((pattern vector-pattern) var)
  • Struct SIMPLE-VECTOR-PATTERN
    No slots.
  • Function SIMPLE-VECTOR-PATTERN-SUBPATTERNS (instance)
  • Function (setf SIMPLE-VECTOR-PATTERN-SUBPATTERNS) (value instance)
  • Function MAKE-SIMPLE-VECTOR-PATTERN (&rest subpatterns)
  • Method CONSTRUCTOR-PATTERN-DESTRUCTOR-SHARABLE-P ((x simple-vector-pattern) (y simple-vector-pattern))
  • Method CONSTRUCTOR-PATTERN-MAKE-DESTRUCTOR ((pattern simple-vector-pattern) var)
  • Struct CLASS-PATTERN
    CLASS-NAME
    SLOT-NAMES
  • Function CLASS-PATTERN-SUBPATTERNS (instance)
  • Function (setf CLASS-PATTERN-SUBPATTERNS) (value instance)
  • Function CLASS-PATTERN-CLASS-NAME (instance)
  • Function (setf CLASS-PATTERN-CLASS-NAME) (value instance)
  • Function CLASS-PATTERN-SLOT-NAMES (instance)
  • Function (setf CLASS-PATTERN-SLOT-NAMES) (value instance)
  • Function MAKE-CLASS-PATTERN (class-name &rest slot-specs)
  • Method CONSTRUCTOR-PATTERN-DESTRUCTOR-SHARABLE-P ((x class-pattern) (y class-pattern))
  • Method CONSTRUCTOR-PATTERN-MAKE-DESTRUCTOR ((pattern class-pattern) var)
  • Struct STRUCTURE-PATTERN
    CONC-NAME
    SLOT-NAMES
  • Function STRUCTURE-PATTERN-SUBPATTERNS (instance)
  • Function (setf STRUCTURE-PATTERN-SUBPATTERNS) (value instance)
  • Function STRUCTURE-PATTERN-CONC-NAME (instance)
  • Function (setf STRUCTURE-PATTERN-CONC-NAME) (value instance)
  • Function STRUCTURE-PATTERN-SLOT-NAMES (instance)
  • Function (setf STRUCTURE-PATTERN-SLOT-NAMES) (value instance)
  • Function MAKE-STRUCTURE-PATTERN (conc-name &rest slot-specs)
  • Method CONSTRUCTOR-PATTERN-DESTRUCTOR-SHARABLE-P ((x structure-pattern) (y structure-pattern))
  • Method CONSTRUCTOR-PATTERN-MAKE-DESTRUCTOR ((pattern structure-pattern) var)
  • Function PATTERN-VARIABLES (pattern)
    Returns the set of variables in PATTERN. If PATTERN is not linear, an error will be raised.
  • Function PLACE-PATTERN-INCLUDED-P (pattern)
  • Function CHECK-PATTERNS (patterns)
    Check if PATTERNS are valid. Otherwise, an error will be raised.
  • Function LIFT-GUARD-PATTERNS (pattern)
  • Function PATTERN-EXPAND-FUNCTION (name)
  • Function (setf PATTERN-EXPAND-FUNCTION) (function name)
  • Function PATTERN-EXPAND-1 (pattern)
  • Function PATTERN-EXPAND (pattern)
  • Function PATTERN-EXPAND-ALL (pattern)
  • Function PARSE-PATTERN (pattern)
  • Generic-Function PARSE-CONSTRUCTOR-PATTERN (name &rest args)
  • Method PARSE-CONSTRUCTOR-PATTERN ((name (eql 'cons)) &rest args)
  • Method PARSE-CONSTRUCTOR-PATTERN ((name (eql 'assoc)) &rest args)
  • Method PARSE-CONSTRUCTOR-PATTERN ((name (eql 'optima:property)) &rest args)
  • Method PARSE-CONSTRUCTOR-PATTERN ((name (eql 'vector)) &rest args)
  • Method PARSE-CONSTRUCTOR-PATTERN ((name (eql 'simple-vector)) &rest args)
  • Method PARSE-CONSTRUCTOR-PATTERN ((name (eql 'class)) &rest args)
  • Method PARSE-CONSTRUCTOR-PATTERN ((name (eql 'structure)) &rest args)
  • Method PARSE-CONSTRUCTOR-PATTERN (name &rest slot-specs)
  • Generic-Function UNPARSE-PATTERN (pattern)
  • Method UNPARSE-PATTERN ((pattern variable-pattern))
  • Method UNPARSE-PATTERN ((pattern place-pattern))
  • Method UNPARSE-PATTERN ((pattern constant-pattern))
  • Method UNPARSE-PATTERN ((pattern guard-pattern))
  • Method UNPARSE-PATTERN ((pattern not-pattern))
  • Method UNPARSE-PATTERN ((pattern or-pattern))
  • Method UNPARSE-PATTERN ((pattern and-pattern))
  • Method UNPARSE-PATTERN ((pattern cons-pattern))
  • Method UNPARSE-PATTERN ((pattern assoc-pattern))
  • Method UNPARSE-PATTERN ((pattern property-pattern))
  • Method UNPARSE-PATTERN ((pattern vector-pattern))
  • Method UNPARSE-PATTERN ((pattern simple-vector-pattern))
  • Method UNPARSE-PATTERN ((pattern class-pattern))
  • Method UNPARSE-PATTERN ((pattern structure-pattern))

OPTIMA

  • Macro 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)))))
  • Macro FAIL
    Causes the latest pattern matching to fail. After this failure, matching continues at the next pattern.
  • Condition MATCH-ERROR  (ERROR)
  • Macro 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 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
  • Macro 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 (arg &body clauses)
    Same as MATCH, except MATCH-ERROR will be raised if not matched.
  • Macro MULTIPLE-VALUE-EMATCH (values-form &body clauses)
    Same as MULTIPLE-VALUE-MATCH, except MATCH-ERROR will be raised if not matched.
  • Macro CMATCH (arg &body clauses)
    Same as MATCH, except a continuable MATCH-ERROR will be raised if none of the clauses match.
  • Macro MULTIPLE-VALUE-CMATCH (values-form &body clauses)
    Same as MULTIPLE-VALUE-MATCH, except a continuable MATCH-ERROR will be raised if none of the clauses match.

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 (pattern arg &body (then &optional else))
    Equivalent to (match ARG (PATTERN THEN) (otherwise ELSE)).
  • Macro WHEN-MATCH (pattern arg &body body)
    Equivalent to (match ARG (PATTERN BODY...)).
  • Macro UNLESS-MATCH (pattern arg &body body)
    Equivalent to (match ARG (PATTERN) (otherwise BODY...)).
  • Macro 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* (bindings &body body)
    Similar to LET-MATCH but matches sequentially.
  • Macro LET-MATCH1 (pattern arg &body body)
    Equivalent to (let-match ((PATTERN ARG)) BODY...).
  • Macro LAMBDA-MATCH (&body clauses)
    Equivalent to (lambda (arg) (match arg CLAUSES...)).
  • Macro LAMBDA-EMATCH (&body clauses)
    Equivalent to (lambda (arg) (ematch arg CLAUSES...)).
  • Macro LAMBDA-CMATCH (&body clauses)
    Equivalent to (lambda (arg) (cmatch arg CLAUSES...)).
  • Macro LAMBDA-MATCH1 (pattern &body body)
    Equivalent to (lambda-match (PATTERN BODY...)).
  • Macro LAMBDA-EMATCH1 (pattern &body body)
    Equivalent to (lambda-ematch (PATTERN BODY...)).
  • Macro LAMBDA-CMATCH1 (pattern &body body)
    Equivalent to (lambda-cmatch (PATTERN BODY...)).

optima.ppcre

CL-PPCRE support for optima

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 the REGEXP matched.

Examples:

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