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: Sebastian Tennant
Subject: Re: A macro and an unwanted containing list in the resulting form
Date: Wed, 23 May 2007 15:51:02 +0300
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.95 (gnu/linux)

Quoth "Juanma Barranquero" <address@hidden>:
> 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)))

Hmm.  Thanks a lot.  It works.  (Now I need to grok exactly why).

> 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"))

The reason for the alist is the clauses are being passed as one of a
number of arguments to a function call.

Thanks again.

Sebastian





reply via email to

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