transcendental-lisp/lisp/lang/dlambda.lisp
Mike Cifelli a21114ac7c Add a GENSYM-EQUAL function for unit testing macros
Some macro definitions were refactored along with their associated
unit tests.
2017-03-13 14:43:31 -04:00

18 lines
526 B
Common Lisp

(load "functions.lisp")
;; This is based on the dlambda macro presented in "Let Over Lambda" by Doug Hoyte.
(defmacro dlambda (&rest methods)
(let ((arguments (gensym)))
`(lambda (&rest ,arguments)
(case (first ,arguments)
,@(mapcar
(lambda (method)
`(,(first method)
(apply (lambda ,@(rest method))
,(if (equal t (first method))
arguments
`(rest ,arguments)))))
methods)))))