Re: splicing with subst
- From: Pascal Bourguignon <pjb@xxxxxxxxxxxxxxxxx>
- Date: Sat, 28 Apr 2007 22:49:29 +0200
Andy Chambers <achambers.home@xxxxxxxxxxxxxx> writes:
On Apr 27, 5:59 pm, Pascal Bourguignon <p...@xxxxxxxxxxxxxxxxx> wrote:
Andy Chambers <achambers.h...@xxxxxxxxxxxxxx> writes:
Hi,
I'd like to transform a tree such that a marker sexp is replaced by an
inline list of sexp's. For example....
'(list
(string)
(marker))
should be replaced with....
'(list
(string)
(one) (two) (three))
Why do you have this form: (quote (list (string) (marker)))
The question was some nitpicking on my part about why did you write
'(list (string) (marker))
instead of: (list (string) (marker))
when you spoke of data.
If you say that you have a list '(a b c)
it means you have a list of two elements, quote and (a b c),
since '(a b c) is equivalent to (quote (a b c))
^ ^ ^
| | |
| | +--- second element
| +--------first element
+-----------a list
Try:
C/USER[57]> (length (read)) ; you enter this program
'(a b c) ; then you enter this data
2 ; and you get this result.
To put a list '(a b c) in a program, to avoid it being evaluated you
have to quote once more:
C/USER[59]> (let ((x ''(a b c)))
(print (length x))
(print (first x))
(print (second x))
x)
2 ; printed
QUOTE ; printed
(A B C) ; printed
'(A B C) ; result, printed by the REPL;
; this is a list of 2 elements:
C/USER[60]> (length *)
2
(a b c) would be equal to the list returned as result of the
evaluation of the form '(a b c) or (quote (a b c)).
So you could say that you have the list resulting from '(a b c),
and this would be understood as being (a b c).
But '(a b c) itself is a list (data), as any non atomic form, and it
_is_ the list containing only quote and (a b c). On the other hand,
'(a b c) is a form (program), which can be _evaluated_ and which would
return the list (a b c). Note that if a was the name of a function,
and b and c the names of variables, (a b c) would also be a form, that
could also be evaluated...
--
__Pascal Bourguignon__ http://www.informatimago.com/
"This statement is false." In Lisp: (defun Q () (eq nil (Q)))
.
- References:
- splicing with subst
- From: Andy Chambers
- Re: splicing with subst
- From: Pascal Bourguignon
- Re: splicing with subst
- From: Andy Chambers
- splicing with subst
- Prev by Date: Re: programmatically determine if argument is list compatible to a given lambda list
- Next by Date: Re: programmatically determine if argument is list compatible to a given lambda list
- Previous by thread: Re: splicing with subst
- Next by thread: What are the domains that lisp doesn't fit int?
- Index(es):
Relevant Pages
|