From: Pascal Bourguignon <pjb@informatimago.com>
To: help-gnu-emacs@gnu.org
Subject: Re: (list) and '(list)
Date: Thu, 26 Apr 2007 23:55:52 +0200 [thread overview]
Message-ID: <87k5vyol5j.fsf@thalassa.lan.informatimago.com> (raw)
In-Reply-To: mailman.2557.1177600988.7795.help-gnu-emacs@gnu.org
A Soare <alinsoar@voila.fr> writes:
> Can somebody tell me if there already is a code that makes the
> distintion between a list that evaluates as a function like
>
> (function ...
>
> and between a list that evaluates to itself :
>
> '(list ... , and its aliases like (quote (list ... etc
A list that evaluates to itself? It cannot start with list. The
function list returns a NEW list, so it will never return the source
list itself.
In your question, there's also a problem with the definition of
'itself'. Most quine programs (which are represented as lists, so
they'd be candidates), don't return themselves (in the sense of eq),
but themselves in the sense of equal.
An easy way to know if the variable x is bound to a list that
evaluates to itself in the sense of equal is:
(and (listp x) (equal x (eval x)))
For example:
(let ((x '((lambda nil
(let ((src "((lambda nil
(let ((src %S))
(car (read-from-string (format src src))))))"))
(car (read-from-string (format src src))))))))
(and (listp x) (equal x (eval x))))
--> t
If you really want to test lists that give themselves in the sense of
eq when evaluated, this restricts the number of such lists a lot, and
you have to use #= and ## to write them:
(let ((x '#1=((lambda nil (quote #1#)))))
(and (listp x) (eq x (eval x))))
--> t
Oh, and there is no way to know what a list evaluates to without
effectively evaluating it, in general (testing whether the car of the
list is list or function is evaluating it, at least partially. If you
want an exact result, you'd need to evaluate it completely).
--
__Pascal Bourguignon__ http://www.informatimago.com/
PLEASE NOTE: Some quantum physics theories suggest that when the
consumer is not directly observing this product, it may cease to
exist or will exist only in a vague and undetermined state.
next parent reply other threads:[~2007-04-26 21:55 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.2557.1177600988.7795.help-gnu-emacs@gnu.org>
2007-04-26 21:55 ` Pascal Bourguignon [this message]
2007-04-27 0:58 ` (list) and '(list) Tim X
2007-04-30 18:53 A Soare
-- strict thread matches above, loose matches on Subject: below --
2007-04-30 18:15 A Soare
2007-04-27 10:37 A Soare
2007-04-26 15:17 A Soare
2007-04-27 10:25 ` Kai Grossjohann
[not found] ` <mailman.2588.1177669955.7795.help-gnu-emacs@gnu.org>
2007-04-27 10:39 ` David Kastrup
2007-04-27 11:05 ` Pascal Bourguignon
2007-04-30 12:49 ` Kai Grossjohann
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87k5vyol5j.fsf@thalassa.lan.informatimago.com \
--to=pjb@informatimago.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).