common-lisp Pattern matching Guard-pattern


Example

Guard patterns can be used to check that a value satisfies an arbitrary test-form.

(dotimes (i 5)
  (format t "~d: ~a~%"
          i (match i
              ((guard x (oddp x)) "Odd!")
              (_ "Even!"))))
; 0: Even!
; 1: Odd!
; 2: Even!
; 3: Odd!
; 4: Even!