help-gnu-emacs
[Top][All Lists]
Advanced

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

RE: Run a program


From: Drew Adams
Subject: RE: Run a program
Date: Wed, 28 Sep 2011 06:44:54 -0700

> Thank very much Deniz, Kevin and Le for your replies and advices.
> (vector 0 0 0) and (make-vector 3 0) work well.
> I understood that my problem was connected with quoting, now 
> I have to read  carefully the thread : buffer-local variables
> seem to remember values (explanations of Drew Adams and others).
> Not obvious,

No, it's not obvious to someone new to Lisp.

To be clear, Le took a shortcut in saying that this has to do with quoting.  In
fact, it does not.

What it comes down to is that the Lisp _reader_ constructs Lisp objects as it
reads sexps (code).  That includes lists, vectors, and symbols.  Nearly every
Lisp sexp you see in a program leads to the Lisp reader constructing a list of
lists, symbols, vectors, strings, etc.  (defun foo ...) becomes a list when it
is read, and so on.

Reading is a separate step from evaluating.  Lisp interpretation is a loop with
these steps: Read (a sexp), Evaluate it, Print (the result) - the so-called REP
Loop, or REPL.  People sometimes gloss over the Read step when thinking about
code, but that can be a mistake, as the gotcha in question shows.
http://en.wikipedia.org/wiki/Read-eval-print_loop

A special form such as `quote' does not receive program text as its argument; it
receives an internal Lisp object already created by the Lisp reader.

Depending on the particular Lisp and its implementation, the reader might or
might not create a new, different list or vector each time it encounters
equivalent text (sexp).  In Emacs Lisp, it typically (always?) does not create a
new one - it reuses the same list or vector.

And that is why you should not modify such a "constant", at least not expecting
a new, distinct constant to have been created at each textual occurrence of the
same sexp.  Those textual occurrences will typically all stand for the same Lisp
object.

This is a gotcha associated with learning Lisp, but once it is learned you have
a better understanding of the kind of language it is.

HTH.




reply via email to

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