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

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

Re: (list) and '(list)


From: Pascal Bourguignon
Subject: Re: (list) and '(list)
Date: Thu, 26 Apr 2007 23:55:52 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.91 (gnu/linux)

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.


reply via email to

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