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

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

Re: (list) and '(list)


From: A Soare
Subject: Re: (list) and '(list)
Date: Fri, 27 Apr 2007 12:37:59 +0200 (CEST)

> The following message is a courtesy copy of an article
> that has been posted to gmane.emacs.help as well.
> 
> 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
> 
> Like the others who responded, it is not clear to me what you want.
> 
> Lisp normally reads code and then evaluates (evals) it.  During
> reading, it performs some (few) conversions such as 'foo to (quote
> foo).  During evaluation, the magic happens:
> 
> - If we are looking at a number or a string, return that number or
>   string.  (Numbers and strings are said to be self-evaluating because
>   they evaluate to themselves.)  If we are looking at some special
>   symbols (like t and nil), return those values.  (t and nil are also
>   self-evaluating.)
> 
> - If we are looking at a list, look at the first element of the list.
>   If it is a function, then eval all other elements of the list, then
>   use the results as arguments to the function (call the function).
>   Then return the result of the function call.
> 
> - The first element can also be a special form.  In this case, the
>   other elements of the list are NOT evaled but instead passed to the
>   special form verbatim.
> 
>   Popular special forms: defun, quote, if, setq
> 
> So in a strict sense, what you can do is:
> 



>   (setq unevaled (read STREAM))
>   (setq evaled (eval unevaled))
>   (equal unevaled evaled)

That is what I wanted to know. Giving a string/[part of a buffer] that 
represents a LISP code, to say if a list inside it defines a function or a 
symbol (that evaluates to itself).

That code solves my problem. Thank you very much.


Alin Soare.





reply via email to

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