all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: TheFlyingDutchman <zzbbaadd@aol.com>
To: help-gnu-emacs@gnu.org
Subject: Re: identity function with an echo side effect
Date: Wed, 11 Aug 2010 19:35:47 -0700 (PDT)	[thread overview]
Message-ID: <4a9f81c6-9763-45bb-ae17-11aaadc198f3@x24g2000pro.googlegroups.com> (raw)
In-Reply-To: 106a3bf2-cd32-4b50-8e99-81e0cad8efa2@j8g2000yqd.googlegroups.com


> (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.


      parent reply	other threads:[~2010-08-12  2:35 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-10 20:56 identity function with an echo side effect bolega
2010-08-10 23:03 ` Pascal J. Bourguignon
2010-08-11  5:01   ` bolega
2010-08-11 14:19     ` Pascal J. Bourguignon
2010-08-11 17:42       ` bolega
2010-08-11 20:43         ` Pascal J. Bourguignon
2010-08-12  2:35         ` TheFlyingDutchman [this message]

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=4a9f81c6-9763-45bb-ae17-11aaadc198f3@x24g2000pro.googlegroups.com \
    --to=zzbbaadd@aol.com \
    --cc=help-gnu-emacs@gnu.org \
    /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.