unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: David Kastrup <dak@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: Macro vs Function
Date: Wed, 12 Apr 2006 13:19:17 +0200	[thread overview]
Message-ID: <85d5fn3utm.fsf@lola.goethe.zz> (raw)
In-Reply-To: <BAY112-F30837797609033FA038DA3DAC20@phx.gbl> (Herbert Euler's message of "Wed, 12 Apr 2006 18:39:19 +0800")

"Herbert Euler" <herberteuler@hotmail.com> writes:

>>From: David Kastrup <dak@gnu.org>
>>To: "Herbert Euler" <herberteuler@hotmail.com>
>>CC: emacs-devel@gnu.org
>>Subject: Re: Macro vs Function
>>Date: Wed, 12 Apr 2006 11:53:25 +0200
>>
>>(defmacro xxx (a) a)
>>(defun yyy (a) a)
>>
>>(xxx (+ 3 4)) => 7
>>(yyy '(+ 3 4)) => (+ 3 4)
>
> I'm confused now.  Take a look at this:
>
>    (defun f ()
>      nil)
>
>    (defmacro m (a)
>      (if a
>          t
>        nil))
>
>    (m (f)) => t
>
> Why does (f) in this example not get evaluated?

Uh, why should it get evaluated?  Macro arguments are _never_
evaluated.  They are passed quoted into the macro, the macro gets
executed, and the return value of the macro gets evaluated.

In the above, m is called with '(f) as its argument.  (if '(a)
... obviously evaluates to t which the macro returns.  Then t gets
evaluated, but since it is a self-quoting form, nothing else happens
with it.

Here is a more complex example:

(defmacro m (a)
  (append a '(2 4)))

(m (+)) => 6

And here is what happens in compilation:

(defun xxx () (m (or)))

M-x disassemble RET xxx RET

byte code for xxx:
  args: nil
0	constant  2
1	return	  

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

  parent reply	other threads:[~2006-04-12 11:19 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-12  8:22 Macro vs Function Herbert Euler
2006-04-12  9:07 ` David Kastrup
2006-04-12  9:17   ` Herbert Euler
2006-04-12  9:24     ` David Kastrup
2006-04-12  9:39       ` Herbert Euler
2006-04-12  9:53         ` David Kastrup
2006-04-12 10:39           ` Herbert Euler
2006-04-12 11:14             ` Andreas Schwab
2006-04-12 11:56               ` Herbert Euler
2006-04-12 12:08                 ` Herbert Euler
2006-04-12 12:19                   ` David Kastrup
2006-04-12 13:37                     ` Herbert Euler
2006-04-12 13:52                       ` David Kastrup
2006-04-12 15:13                         ` Herbert Euler
2006-04-12 15:26                           ` Stuart D. Herring
2006-04-12 15:54                             ` Herbert Euler
2006-04-12 15:29                           ` David Kastrup
2006-04-12 15:56                             ` Herbert Euler
2006-04-12 16:14                               ` Herbert Euler
2006-04-12 16:59                               ` David Kastrup
2006-04-13  2:17                                 ` Herbert Euler
2006-04-12 12:12                 ` David Kastrup
2006-04-12 11:19             ` David Kastrup [this message]
  -- strict thread matches above, loose matches on Subject: below --
2006-04-12 12:05 Herbert Euler
2006-04-12 12:13 ` David Kastrup
2006-04-12 12:17   ` Herbert Euler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=85d5fn3utm.fsf@lola.goethe.zz \
    --to=dak@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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