all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Pascal J. Bourguignon" <pjb@informatimago.com>
To: help-gnu-emacs@gnu.org
Subject: Re: understanding backquote
Date: Tue, 02 Jun 2015 22:03:58 +0200	[thread overview]
Message-ID: <87oakx513l.fsf@kuiper.lan.informatimago.com> (raw)
In-Reply-To: mailman.4175.1433272668.904.help-gnu-emacs@gnu.org

Olaf Rogalsky <olaf.rogalsky@aol.de> 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


  parent reply	other threads:[~2015-06-02 20:03 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-02 13:28 gtags-find-tag and gtags-find-rtag in C-code Peter Münster
2015-06-02 15:06 ` Eli Zaretskii
2015-06-02 16:01   ` Peter Münster
2015-06-02 16:13     ` Eli Zaretskii
2015-06-02 19:09       ` Dmitry Gutov
2015-06-02 20:34       ` Peter Münster
2015-06-02 19:17 ` understanding backquote Olaf Rogalsky
2015-06-03 11:05   ` Nicolas Richard
     [not found]   ` <mailman.4231.1433345880.904.help-gnu-emacs@gnu.org>
2015-06-03 18:53     ` Stefan Monnier
     [not found] ` <mailman.4175.1433272668.904.help-gnu-emacs@gnu.org>
2015-06-02 20:03   ` Pascal J. Bourguignon [this message]
2015-06-02 23:00     ` Olaf Rogalsky
2015-06-03 10:40       ` Nicolas Richard
     [not found]     ` <mailman.4191.1433286041.904.help-gnu-emacs@gnu.org>
2015-06-02 23:08       ` Pascal J. Bourguignon
2015-06-02 21:22   ` Barry Margolin
2015-06-02 22:53     ` Olaf Rogalsky
     [not found]     ` <mailman.4189.1433285612.904.help-gnu-emacs@gnu.org>
2015-06-02 23:07       ` Pascal J. Bourguignon
2015-06-02 23:54         ` Olaf Rogalsky
     [not found]         ` <mailman.4193.1433289260.904.help-gnu-emacs@gnu.org>
2015-06-03  1:14           ` Stefan Monnier
2015-06-03  7:57             ` Olaf Rogalsky
2015-06-03 10:23               ` Olaf Rogalsky
2015-06-03  2:37           ` Pascal J. Bourguignon

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

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

  git send-email \
    --in-reply-to=87oakx513l.fsf@kuiper.lan.informatimago.com \
    --to=pjb@informatimago.com \
    --cc=help-gnu-emacs@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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.