Multicase
Macro that allows matching on multiple sum types or enums at once.
Usage:
(multicase macro-pairs cases)
where:
- macro-pairs is a list of pairs (casetype variable). The casetype says
how to check cases on the variable. The outermost IF structure will be
generated by the first pair, then inner IFs generated from the subsequent
pairs.
- casetype is either a (symbol) casemacro, or a form (LIST casemacro
varname*). The LIST form assumes the variable is a list of a type compatible
with casemacro. The varnames will be used to bind the elements of the
list. There should be at least as many varnames as the corresponding matches in
the cases (below).
- cases is a list of forms (match [ :when cond ] value)
- match is either a wildcard &, -, or :otherwise (all with
the same meaning) or else a list the same length as macro-pairs, where the
element corresponding to a given casetype/variable pair is either:
- a wildcard
- a value/keyword appropriate for the given casemacro
- for the LIST casetype, a list of wildcards/values for the casemacro, of length less than or equal to the number of variables porovided in the casetype.
- cond and value are terms.
Instructive examples can be found in books/centaur/fty/tests/multicase.lisp.
This macro depends on other case macros such as those generated by deftagsum, defflexsum, deftranssum, and def-enumcase. In particular, it depends on these case macros allowing an :otherwise* keyword which acts as a wildcard but disappears (without error) when the other cases are exhaustive.
A couple of additional related macros fty::case* and
fty::case*-equal provide compatibile case macros for checking arbitrary
values: case* works with EQLable objects and case*-equal works with
arbitrary objects.