[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Alternate format for datetree

From: Nick Dokos
Subject: Re: [O] Alternate format for datetree
Date: Thu, 06 Sep 2012 02:26:05 -0400

c b <address@hidden> wrote:

> Thank a lot for your suggestions. I finally got it working. It took a while
> to figure out that the back-tick is different from the quote.
> I am an elisp newbie. Is there an easy explanation of why we need a
> back-tick vs. quote?

quote says: take the next expression as is - do not evaluate anything in it.

backquote says: take the next expression as is - do not evaluate
          anything in it, *except* do evaluate any subexpression
          preceded by a comma and put the result back into the original
          expression in place of the comma-ed subexpression.


'(a b c) -> (a b c)
`(a b c) -> (a b c)  ; because there is no comma

'(a (+ 2 3)) -> (a (+ 2 3))
`(a (+ 2 3)) -> (a (+ 2 3)) ; again no comma
`(a ,(+ 2 3)) -> (a 5)

Incidentally, if you switch to the *scratch* buffer (which is in Lisp
Interaction mode), you can type these expressions in and evaluate each
one by pressing C-j at the end of each expression.

So they both quote: the first one unconditionally, the second mostly but
allowing partial evaluation of subexpressions.

BTW, '(a b c) is shorthand for (quote (a b c)): internally, the lisp
reader translates the first to the second and then the evaluator
evaluates the quote form, returning its (unevaluated) argument: that's
why quote is a "special form" - by contrast, ordinary functions always
evaluate their arguments.

`(a b ,(+ 2 3)) is also shorthand for (backquote (a b ,(+ 2 3))) but the
implementation is necessarily more complicated: backquote is implemented
as a macro (because it is a special form, its argument is not evaluated,
so it cannot be implemented as a function; it has to be implemented as a
macro), but then backquote has to dig into the structure to look for ,
(and also for the somewhat different ,@ construct - see the docs) and do what's

Another example is provided by the docstring of backquote itself: C-h f
backquote RET to see it.

For more info, see the elisp manual, chapter 9 on evaluation:

     (info "(elisp) Evaluation")

and two sections therein in particular, 9.3 Quoting, and 9.4 Backquote:

    (info "(elisp) Quoting")
    (info "(elisp) Backquote")


reply via email to

[Prev in Thread] Current Thread [Next in Thread]