eval-let macro help?

Discussion of Common Lisp
fitzgen
Posts: 6
Joined: Mon May 17, 2010 12:42 pm

Re: eval-let macro help?

Post by fitzgen » Thu May 20, 2010 11:57 am

I got "cond-match" and "defun-match" working too! Having so much fun with 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)))
If anyone is interested, I have thrown the whole of the code up on github: http://github.com/fitzgen/cl-pattern-ma ... ching.lisp

Post Reply