Project's home: http://www.hexstreamsoft.com/projects/cartesian-product-switch/
CARTESIAN-PRODUCT-SWITCH is a macro for choosing the appropriate form
to execute according to the combined results of multiple tests. This is a
straightforward and efficient alternative to the convoluted ad-hoc
conditionals one might otherwise resort to.
cartesian-product-switch was born as cartesian-product-case but a
fairly obvious limitation was soon discovered, prompting a redesign
and library name change. Further features and extensibility were also
Here's an example:
(let ((manner :flip) (direction :backward))
(cartesian-product-switch ((case manner
(error "Walking in-place is too boring!")
"Awkwardly walking backwards..."
(t (error "Don't know how to ~A while going ~A." manner direction))))
Currently supported testclause kinds:
(case ccase ecase typecase ctypecase etypecase if cond svref)
It's also possible to make your own kinds.
Check definitions.lisp in particular for inspiration.
In a nutshell, call (cartesian-product-switch:define operator (args) body),
where BODY must return 3 values:
A form evaluating to a non-negative integer less than SELECTION-COUNT.
The number of possibilities this testclause introduces.
If true, then the SELECTION-FORM can evaluate to NIL to trigger the "default".
This library is in the Public Domain.
See the UNLICENSE file for details.