[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: (list) and '(list)
From: |
Kai Grossjohann |
Subject: |
Re: (list) and '(list) |
Date: |
Fri, 27 Apr 2007 12:25:56 +0200 |
User-agent: |
Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.97 (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
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)
This is, read it first, then eval it and compare whether the result of
reading and the result of evaling are equal.
Perhaps what you want is to write a special form yourself? That can't
be done in a strict sense, but you can use macros to approximate the
effect.
For example, to reverse the condition of `if' (proof of concept only,
not production code):
(defmacro ifnot (test no yes)
(if (not test) no yes))
Does that help?
Kai
- (list) and '(list), A Soare, 2007/04/26
- Re: (list) and '(list),
Kai Grossjohann <=
- Message not available
- Message not available
- Re: (list) and '(list), Pascal Bourguignon, 2007/04/26
- Re: (list) and '(list), Tim X, 2007/04/26
- Re: (list) and '(list), A Soare, 2007/04/27
- Re: (list) and '(list), A Soare, 2007/04/30
- Re: (list) and '(list), A Soare, 2007/04/30