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: Pascal Bourguignon
Subject: Re: A macro and an unwanted containing list in the resulting form
Date: Wed, 23 May 2007 18:57:40 +0200
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.0.99 (gnu/linux)

Sebastian Tennant <address@hidden> writes:
>> 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.

If you get the a-list as argument to a function, then you don't need a
macro to process it!   Just write a loop!

(require 'cl)

(defun my-function (string clauses)
  (loop
      for clause in clauses
      until (string= string (car clause))
      finally (eval (cdr clause))))

(my-function "goodbye" '(("hello"   . (message "hi"))
                         ("goodbye" . (message "bye"))))


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

NOTE: The most fundamental particles in this product are held
together by a "gluing" force about which little is currently known
and whose adhesive power can therefore not be permanently
guaranteed.


reply via email to

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