NB: the clauses wil be compiled at macro expansion time.
(defmacro match-case (form &rest clauses)
"NB: the clauses wil be compiled at macro expansion time."
(destructuring-bind ((spec &rest body) &rest other-clauses) clauses
(with-unique-names (form-sym matched-p dummy bindings)
(multiple-value-bind (matcher-func vars)
(declare (ignore matcher-func))
`(let ((,form-sym ,form))
(multiple-value-bind (,matched-p ,dummy ,bindings)
(match (make-matcher ',spec) ,form-sym)
(declare (ignore ,dummy) (ignorable ,bindings))
,@(mapcar (lambda (var-name)
`(setf ,var-name (cdr (assoc ',var-name ,bindings))))
(match-case ,form-sym ,@other-clauses)))))))))Source Context