common-lisp Pattern matching defun-match


Example

Using pattern matching one can intertwine function definition and pattern matching, similar to SML.

(trivia:defun-match fib (index)
  "Return the corresponding term for INDEX."
  (0 1)
  (1 1)
  (index (+ (fib (1- index)) (fib (- index 2)))))

(fib 5)
;; => 8