CL Unification: Macro MATCH-CASE
 

Macro MATCH-CASE

Package:

COMMON-LISP.EXTENSIONS.DATA-AND-CONTROL-FLOW.UNIFICATION

Syntax:

  match-case (object &key errorp) <clause>*
  => results*
  

  <clause>         ::= <regular clause> | <default clause>
  <regular clause> ::= (template &body forms)
  <default clause> ::= (t &body forms)
                   |   (otherwise &body forms)
  

Arguments and Values:

template---a unification template

object---an object

substitution---a substitution

errorp---a generalized boolean

error-value---an object

forms---an implicit progn

results---the values returned by forms

Description:

MATCH-CASE sets up a CASE-like environment for multiple template matching clauses. Each clause evaluates its forms in an environment where the variables present in the template are bound lexically. Note that both variable names '?FOO' and 'FOO' are bound for convenience.

The values returned by the MATCH-CASE form are those of the last form in the first clause that satisfies the match test. I.e. the first clause for which the template UNIFYes against object.

If errorp is non-NIL then if none of the regular clauses matches, then an error of type UNIFICATION-NON-EXHAUSTIVE is signalled, regardless of any default clause. Otherwise, the default clause behaves as a standard COND default clause. The default value of errorp is NIL.

Affected By:

None.

Exceptional Situations:

See above.

See Also:

UNIFY, UNIFICATION-FAILURE, UNIFICATION-NON-EXHAUSTIVE

Notes:

Note that UNIFICATION-FAILUREs raising from the evaluation of forms in each clause will not be caught and handled by the enclosing MATCH-CASE block.