Search found 6 matches
- Thu May 20, 2010 11:57 am
- Forum: Common Lisp
- Topic: eval-let macro help?
- Replies: 10
- Views: 8082
Re: eval-let macro help?
I got "cond-match" and "defun-match" working too! Having so much fun with Lisp! (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))) `(m...
- Wed May 19, 2010 5:57 pm
- Forum: Common Lisp
- Topic: eval-let macro help?
- Replies: 10
- Views: 8082
Re: eval-let macro help?
If anyone is still interested, I successfully got it working, and this is what I ended up with: ;; ... snip ... (defun extract-variables (pattern) (remove-if-not #'variable? (flatten pattern))) (defun make-let-list (variables alist) (mapcar #'(lambda (var) `(,var (cdr (assoc ',var ,alist)))) variabl...
- Wed May 19, 2010 10:18 am
- Forum: Common Lisp
- Topic: eval-let macro help?
- Replies: 10
- Views: 8082
Re: eval-let macro help?
Then, make sure the macro to expand this: (let-match ((?H . ?T) '(1 2 3 4)) (list ?H ?T)) into something like this: (let ((alist (pat-match '(?H . ?T) '(1 2 3 4)))) (let ((?H (cdr (assoc '?H alist))) (?T (cdr (assoc '?T alist)))) (list ?H ?T))) That will work :) (alist will be a gensym, of course) ...
- Tue May 18, 2010 8:12 pm
- Forum: Common Lisp
- Topic: eval-let macro help?
- Replies: 10
- Views: 8082
Re: eval-let macro help?
If you could post what you are trying to do, we could give you better ideas. I have been reading Norvig's PAIP, and wanted to write some macros to better integrate pattern matching in to CL. Basically, I started with something based on http://norvig.com/paip/patmatch.lisp and since then, this is pr...
- Tue May 18, 2010 7:52 pm
- Forum: Common Lisp
- Topic: eval-let macro help?
- Replies: 10
- Views: 8082
Re: eval-let macro help?
When writing macros, always start with the macroexpanded code, then develop a macro to output that based on your source form. What do you want the expansion of (eval-let foo (* bar bar)) to look like? Well, in the case of (let ((foo '((bar 5)))) (eval-let foo (* bar bar))) I would want the eval-let...
- Tue May 18, 2010 7:02 pm
- Forum: Common Lisp
- Topic: eval-let macro help?
- Replies: 10
- Views: 8082
eval-let macro help?
I don't have a ton of experience with CL, so please bear with me :) As a helper to another macro I'm writing, I need a macro that is exactly like let, but evaluates its first argument (which should evaluate to a let list) and then drops it into a simple let expression. This was my first attempt: (de...