cartesian-product-switch
A simple operator overlay macro in Quicklisp.
| Project Type | Library | |
|---|---|---|
| Programming language | Common Lisp | |
| Status | Ready-to-use | |
| License | Public Domain | |
| Library type | Operator overlay macro | |
| Project complexity | Simple | |
| Latest release | Version | 2.0 |
| Date | 2 sept 2012 | |
|
Quicklisp
(Sept 2012 dist and later) |
Status | Available |
| Version | Latest | |
External library pages
| Depends on | Depended on by | |
|---|---|---|
| Directly | ||
| Indirectly | Nothing | Nothing |
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.
(let ((manner :flip) (direction :backward))
(cartesian-product-switch ((case manner
:walk
:flip)
(case direction
:forward
:in-place
:backward))
"Walking..."
(error "Walking in-place is too boring!")
"Awkwardly walking backwards..."
"Frontflip!"
"Jumping in-place."
"Backflip!"
(t (error "Don't know how to ~A while going ~A." manner direction))))
To use cartesian-product-switch, simply (:import-from #:cartesian-product-switch #:cartesian-product-switch). Don't (:use)!
Currently supported testclause kinds:
caseccaseecasetypecasectypecaseetypecaseifcondsvref
It's also possible to make your own kinds. Check definitions.lisp in particular for inspiration. In a nutshell, call (, where body must return 3 values:cartesian-product-switch:define operator (args) body)
- selection-form
A form evaluating to a non-negative integer less than selection-count.
- selection-count
The number of possibilities this testclause introduces.
- defaultp
If true, then the selection-form can evaluate to
nilto trigger the "default".