[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
A macro and an unwanted containing list in the resulting form
From: |
Sebastian Tennant |
Subject: |
A macro and an unwanted containing list in the resulting form |
Date: |
Wed, 23 May 2007 14:28:07 +0300 |
User-agent: |
Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.95 (gnu/linux) |
Hi all,
Trying to write a little macro to automate building a (cond ...)
expression from an alist, where the alist is of the form:
(("string" . FORM) ...)
and FORM is evaluated if the string passes an equality test.
Here's where I've got to so far. As you can see, the cond clauses are
contained within an unwanted list:
(defmacro build-cond (alist)
(list 'cond
(mapcar '(lambda (each)
(cons (list 'equal 'my-var (car each)) (list (cdr each))))
alist)))
(macroexpand '(build-cond (("hello" . (message "hi"))
("goodbye" . (message "bye")))
))
(cond (((equal e "hello") (message "hi"))
^((equal e "goodbye") (message "bye"))))
| ^
| |
+--------- unwanted list -------------+
Clearly my approach is wrong (because this is how mapcar behaves), so
what is the best way to go about this?
TIA
Sebastian