From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Pascal J. Bourguignon" Newsgroups: gmane.emacs.help Subject: Re: understanding backquote Date: Tue, 02 Jun 2015 22:03:58 +0200 Organization: Informatimago Message-ID: <87oakx513l.fsf@kuiper.lan.informatimago.com> References: <87vbf65jem.fsf@free.fr> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1433275543 13639 80.91.229.3 (2 Jun 2015 20:05:43 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 2 Jun 2015 20:05:43 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Jun 02 22:05:31 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YzsR4-0006wN-LD for geh-help-gnu-emacs@m.gmane.org; Tue, 02 Jun 2015 22:05:18 +0200 Original-Received: from localhost ([::1]:60738 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YzsR4-0008L8-10 for geh-help-gnu-emacs@m.gmane.org; Tue, 02 Jun 2015 16:05:18 -0400 Original-Path: usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 75 Original-X-Trace: individual.net jZj6AGiXl0nSc3mCytqF8QHra97dE/zqXsOpuAXJ7+rTM2TVGe Cancel-Lock: sha1:MWVjYzFmMmQwZWYxMzIwYTI0YWYyNGI0MDViNGUzMWU1Y2NkMmY1NA== sha1:+vTIJxlMXCowJwcUx/1yhJGb9FM= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Original-Xref: usenet.stanford.edu gnu.emacs.help:212435 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:104719 Archived-At: Olaf Rogalsky writes: > Hi, > > I have problems in understanding the semantics of backquote. Consider > the following function: > > (defun test () `,(* (+ 1 2) (+ 3 4))) > > Now let's have a look at the defintion of the symbol: > > (symbol-function 'test) > => (lambda nil (* (+ 1 2) (+ 3 4))) > > Huhh??? I was thinking, that the above definition is equivalent to the > following: > > (defun test () 21) > > Ok, this was unexpected, but perhaps the compiler does it "right": > (disassemble (byte-compile 'test)) > => byte code: > args: nil > 0 constant 21 > 1 return > > Yes, it does. It is only, that I suspect, that this has nothing to do > with backquotes, but rather with constant folding optimization. > > Can anybody explain this to me? `,x is equivalent to x. (info "(elisp) Backquote") More details are given in the Common Lisp specification of the backquote reader macro, but it's "extrapolation" relative to emacs lisp: http://www.lispworks.com/documentation/HyperSpec/Body/02_df.htm Now, the fact that you obtain a simple constant function is unrelated to the backquote, but comes from the fact that you have a good and smart compiler, that notices that the expression is a constant expression, and therefore it is reduced at compilation time: (disassemble (byte-compile (lambda nil (* (+ 1 2) (+ 3 4))))) byte code: args: nil 0 constant 21 1 return With variables, it is another matter: (disassemble (byte-compile (lambda (a b c d) `,(* (+ a b) (+ c d))))) byte code: args: (a b c d) 0 varref a 1 varref b 2 plus 3 varref c 4 varref d 5 plus 6 mult 7 return -- __Pascal Bourguignon__ http://www.informatimago.com/ “The factory of the future will have only two employees, a man and a dog. The man will be there to feed the dog. The dog will be there to keep the man from touching the equipment.” -- Carl Bass CEO Autodesk