Project author Jean-Philippe Paradis
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
(Sept 2012 dist and later)
Status Available
Version Latest

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
                             (case direction
    (error "Walking in-place is too boring!")
    "Awkwardly walking backwards..."
    "Jumping in-place."
    (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:

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".