From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Kastrup Newsgroups: gmane.emacs.devel Subject: Re: Macro vs Function Date: Wed, 12 Apr 2006 13:19:17 +0200 Message-ID: <85d5fn3utm.fsf@lola.goethe.zz> References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1144842305 31150 80.91.229.2 (12 Apr 2006 11:45:05 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 12 Apr 2006 11:45:05 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Apr 12 13:45:02 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1FTdm7-00050p-4F for ged-emacs-devel@m.gmane.org; Wed, 12 Apr 2006 13:44:43 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FTdm6-0003LC-DX for ged-emacs-devel@m.gmane.org; Wed, 12 Apr 2006 07:44:42 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1FTdlk-0003Ky-T6 for emacs-devel@gnu.org; Wed, 12 Apr 2006 07:44:20 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1FTdlj-0003Kd-EZ for emacs-devel@gnu.org; Wed, 12 Apr 2006 07:44:19 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FTdlj-0003Ka-7t for emacs-devel@gnu.org; Wed, 12 Apr 2006 07:44:19 -0400 Original-Received: from [199.232.76.164] (helo=fencepost.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.52) id 1FTdqo-0001jN-CZ for emacs-devel@gnu.org; Wed, 12 Apr 2006 07:49:34 -0400 Original-Received: from localhost ([127.0.0.1] helo=lola.goethe.zz) by fencepost.gnu.org with esmtp (Exim 4.34) id 1FTdli-0004UF-JF; Wed, 12 Apr 2006 07:44:18 -0400 Original-Received: by lola.goethe.zz (Postfix, from userid 1002) id 99F881C3DB49; Wed, 12 Apr 2006 13:19:17 +0200 (CEST) Original-To: "Herbert Euler" In-Reply-To: (Herbert Euler's message of "Wed, 12 Apr 2006 18:39:19 +0800") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:52746 Archived-At: "Herbert Euler" writes: >>From: David Kastrup >>To: "Herbert Euler" >>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