[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: identity function with an echo side effect
From: |
TheFlyingDutchman |
Subject: |
Re: identity function with an echo side effect |
Date: |
Wed, 08 Dec 2010 15:24:20 -0000 |
User-agent: |
G2/1.0 |
> (cdr (print (cdr (print (cdr (print (a b c d))))))) C-x C-e
>
> gives this error if I remove the quote. why ? I get errors if I remove
> all prints. This means if the first cdr required quoted list, then the
> rest must also require it. Hence, an implicit quotation might be
> occurring as in setq ?
Each cdr requires the same thing - a list object. The first cdr does
not receive "(a b c d)" as its argument, it receives that list literal
turned into its in-memory representation as a list object. Each cdr
returns a list object (the internal format - not a string literal) to
the next cdr.
The Emacs Lisp interpreter has to turn the (a b c d) "list literal"
into a list object before passing it to the first cdr function.
However, Emacs Lisp has a problem that most languages do not have. A
list literal looks exactly the same as a function call. e.g.:
(min a b) => Emacs Lisp function call OR Emacs Lisp list literal
The above could be a list, with symbols min, a and b. Or it could be a
function call of min with parameters a and b. In contrast, the Python
interpreter would not have a problem differentiating between the two
because there is different syntax for each:
min(a ,b) => Python function call [min, a, b] => Python list
literal
So how does the Emacs Lisp interpreter differentiate between a
function call and a list literal? It doesn't. It assumes everything is
a function call - or similar expression (macro, special form). If you
are actually writing a list literal and not an expression to evaluate,
you have to explicitly tell the Emacs Lisp interpreter not to evaluate
it as an expression, but to just store it as a list object.
so (a b c d) to Emacs Lisp is a call to the function of symbol a, and
it should pass b, c and d as parameters. '(a b c d) or (quote (a b
c d)) tells Emacs Lisp not to try and execute any function stored in a
- just store the whole thing as a list internally.