[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: understanding backquote
From: |
Barry Margolin |
Subject: |
Re: understanding backquote |
Date: |
Tue, 02 Jun 2015 17:22:01 -0400 |
User-agent: |
MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) |
In article <mailman.4175.1433272668.904.help-gnu-emacs@gnu.org>,
Olaf Rogalsky <olaf.rogalsky@aol.de> wrote:
> 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?
Backquote and comma operate at read time. The comma means "Don't quote
this part", so it will be evaluated when the code is run. It doesn't get
evaluated at read time, though, because that would mess up if it has
variable references, e.g.
(defun test (a) `,(+ 1 a))
If you looked at this function, it would have to be
(lambda (a) (+ 1 a))
It can't be folded at read time.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
- Re: gtags-find-tag and gtags-find-rtag in C-code, (continued)
understanding backquote, Olaf Rogalsky, 2015/06/02
Message not available
Message not available
- Re: understanding backquote,
Barry Margolin <=
- Re: understanding backquote, Olaf Rogalsky, 2015/06/02
- Message not available
- Re: understanding backquote, Pascal J. Bourguignon, 2015/06/02
- Re: understanding backquote, Olaf Rogalsky, 2015/06/02
- Message not available
- Re: understanding backquote, Stefan Monnier, 2015/06/02
- Re: understanding backquote, Olaf Rogalsky, 2015/06/03
- Re: understanding backquote, Olaf Rogalsky, 2015/06/03
Message not availableRe: understanding backquote, Pascal J. Bourguignon, 2015/06/02