help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A macro and an unwanted containing list in the resulting form


From: Juanma Barranquero
Subject: Re: A macro and an unwanted containing list in the resulting form
Date: Wed, 23 May 2007 13:39:54 +0200

On 5/23/07, Sebastian Tennant <address@hidden> wrote:


  (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?

Try with

 (defmacro build-cond (alist)
   (append '(cond)
           (mapcar '(lambda (each)
                     (cons (list 'equal 'my-var (car each)) (list (cdr each))))
                   alist)))

Is there any reason to make the argument of build-cond an alist? You could try

(defmacro build-cond (&rest conds)
 (append '(cond)
         (mapcar '(lambda (each)
                   (cons (list 'equal 'my-var (car each)) (list (cdr each))))
                 conds)))

and then use

 (build-cond ("hello" . (message "hi"))
             ("goodbye" . (message "bye"))

            Juanma




reply via email to

[Prev in Thread] Current Thread [Next in Thread]