Re: eval-let macro help?
Posted: Thu May 20, 2010 11:57 am
I got "cond-match" and "defun-match" working too! Having so much fun with Lisp!
If anyone is interested, I have thrown the whole of the code up on github: http://github.com/fitzgen/cl-pattern-ma ... ching.lisp
Code: Select all
(defun clause-pattern (clause)
(car clause))
(defun clause-body (clause)
(cdr clause))
(defun expand-clauses (form clauses)
(if (null clauses)
nil
(let ((first (car clauses))
(rest (cdr clauses)))
`(multiple-value-bind (ret-val match?) (let-match (,(clause-pattern first) ,form)
,@(clause-body first))
(if match?
ret-val
,(expand-clauses form rest))))))
(defmacro cond-match (form &body clauses)
(expand-clauses form clauses))
(defmacro defun-match (name &rest clauses)
`(defun ,name (&rest args)
(cond-match args
,@clauses)))