emacs-devel
[Top][All Lists]
Advanced

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

Re: Macro vs Function


From: Herbert Euler
Subject: Re: Macro vs Function
Date: Thu, 13 Apr 2006 10:17:01 +0800

From: David Kastrup <address@hidden>
To: "Herbert Euler" <address@hidden>
CC: address@hidden
Subject: Re: Macro vs Function
Date: Wed, 12 Apr 2006 18:59:45 +0200

"Herbert Euler" <address@hidden> writes:

>>From: David Kastrup <address@hidden>
>>To: "Herbert Euler" <address@hidden>
>>CC: address@hidden
>>Subject: Re: Macro vs Function
>>Date: Wed, 12 Apr 2006 17:29:40 +0200
>>
>>Why are you bothering with "apply" in the first place?  It does not
>>look like you have any need for it.  Just write
>
> Because func is supposed to be a variable set by, for instance,
>
>    (setq f '+)
>
> And '+ is just for testing purpose.

Could you _please_ quote the relevant definitions when answering?  It
causes a lot of extra work if I have to go constantly to previous
parts of the thread to dig them out.

I'm sorry.

I still don't see why you can't just write

(defmacro xgp-casi2-safe-call-iter (func largs)
 (and largs
     `(condition-case nil
           (funcall ,func ,@(car largs))
         (error (xgp-casi2-safe-call-iter ,func ,(cdr largs))))))

Or, if you really insist on "apply",

(defmacro xgp-casi2-safe-call-iter (func largs)
 (and largs
     `(condition-case nil
           (apply ,func (list ,@(car largs)))
         (error (xgp-casi2-safe-call-iter ,func ,(cdr largs))))))

Yes, these two both work.  When I wrote the "complete
and utter contorted mess":

(defmacro xgp-casi2-safe-call-iter (func largs)
  (if largs
      `(condition-case nil
           (apply ,func ,((lambda (a) `(quote ,(car a))) largs))
         (error (xgp-casi2-safe-call-iter ,func ,(cdr largs))))
    'nil))

I didn't understand the mechanism of macros.  If I'm writing
them now, I too will write simple ones like what Stuart D.
Herring and you write.

Thank you very much, for making me understand how macro
works.

Sincerely yours,
Guanpeng Xu

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/





reply via email to

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