all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Drew Adams" <drew.adams@oracle.com>
To: "'Roland Thiers'" <roland.thiers@canl.nc>, <help-gnu-emacs@gnu.org>
Subject: RE: Run a program
Date: Wed, 28 Sep 2011 06:44:54 -0700	[thread overview]
Message-ID: <1F2E505FE86947FA9696A4B268046041@us.oracle.com> (raw)
In-Reply-To: <B1380275-25EE-4A7D-B821-B587A4148532@canl.nc>

> 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	other threads:[~2011-09-28 13:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-27  5:28 Run a program Roland Thiers
2011-09-27 21:06 ` Deniz Dogan
2011-09-28  1:43 ` Le Wang
2011-09-28  9:15   ` Roland Thiers
2011-09-28 13:44     ` Drew Adams [this message]
  -- strict thread matches above, loose matches on Subject: below --
2011-09-27 22:01 Buchs, Kevin

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=1F2E505FE86947FA9696A4B268046041@us.oracle.com \
    --to=drew.adams@oracle.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=roland.thiers@canl.nc \
    /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.