unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* A macro and an unwanted containing list in the resulting form
@ 2007-05-23 11:28 Sebastian Tennant
  2007-05-23 11:39 ` Juanma Barranquero
  0 siblings, 1 reply; 13+ messages in thread
From: Sebastian Tennant @ 2007-05-23 11:28 UTC (permalink / raw)
  To: help-gnu-emacs

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

^ permalink raw reply	[flat|nested] 13+ messages in thread
[parent not found: <mailman.1062.1179919591.32220.help-gnu-emacs@gnu.org>]

end of thread, other threads:[~2007-05-24 16:12 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-23 11:28 A macro and an unwanted containing list in the resulting form Sebastian Tennant
2007-05-23 11:39 ` Juanma Barranquero
2007-05-23 12:51   ` Sebastian Tennant
2007-05-23 13:14     ` Juanma Barranquero
2007-05-23 21:40       ` Sebastian Tennant
     [not found]   ` <mailman.1069.1179924576.32220.help-gnu-emacs@gnu.org>
2007-05-23 16:57     ` Pascal Bourguignon
2007-05-23 21:45       ` Sebastian Tennant
     [not found]       ` <mailman.1113.1179959874.32220.help-gnu-emacs@gnu.org>
2007-05-24  8:47         ` Tim X
2007-05-24 13:49           ` Sebastian Tennant
2007-05-24 16:12       ` Johan Bockgård
     [not found] <mailman.1062.1179919591.32220.help-gnu-emacs@gnu.org>
2007-05-23 12:04 ` Pascal Bourguignon
2007-05-23 21:32   ` Sebastian Tennant
     [not found]   ` <mailman.1104.1179956594.32220.help-gnu-emacs@gnu.org>
2007-05-23 23:48     ` Pascal Bourguignon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).