previous up next     contents index
Next: Code Generation Up: Definition Previous: Patterns

Match Failure

If no clause matches the value, the default action is to invoke the procedure match:error with the value that did not match. The default definition of match:error calls error with an appropriate message:

> (match 1 [2 2])

Error: no clause matched 1.
For most situations, this behavior is adequate, but it can be changed either by redefining match:error, or by altering the value of the variable match:error-control. Valid values for match:error-control are:

tabular319

Setting match:error-control to 'match causes the entire match expression to be quoted and passed as a second argument to match:error. The default definition of match:error then prints the match expression before calling error; this can help identify which expression failed to match. This option causes the macros to generate somewhat larger code, since each match expression includes a quoted representation of itself.

Setting match:error-control to 'fail permits the macros to generate faster and more compact code than 'error or 'match. The generated code omits pair? tests when the consequence is to fail in car or cdr rather than call match:error.

Finally, if match:error-control is set to 'unspecified, non-matching expressions will either fail in car or cdr, or return an unspecified value. This results in still more compact code, but is unsafe.



PLT