Example under "assoc" :
(setq values '((x . 100) (y . 200) (z . 50))) => ((X . 100) (Y .
200) (Z . 50))
(assoc 'y values) => (Y . 200)
(rplacd (assoc 'y values) 201) => (Y . 201)
In the first line, "values" is assigned a literal expression, and in
the last line, that literal expression is modified. Is this asking for
trouble?
Johnny wrote:
> Example under "assoc" :
>
>
> (setq values '((x . 100) (y . 200) (z . 50))) => ((X . 100) (Y .
> 200) (Z . 50))
> (assoc 'y values) => (Y . 200)
> (rplacd (assoc 'y values) 201) => (Y . 201)
>
>
> In the first line, "values" is assigned a literal expression, and in
> the last line, that literal expression is modified. Is this asking for
> trouble?
Yeah, I have noticed that myself. It's a disease. Every introductory
text does the same (cheat a little to make examples more succinct),
which is why a rite of passage for Lisp newbies is to emulate that
example and be excoriated on c.l.l. for modifying a literal. :)
kt
--
Cells? Cello? Celtik?: http://www.common-lisp.net/project/cells/
Why Lisp? http://alu.cliki.net/RtL%20Highlight%20Film
Kenny Tilton <·······@nyc.rr.com> writes:
> Johnny wrote:
>
> > Example under "assoc" :
> > (setq values '((x . 100) (y . 200) (z . 50))) => ((X . 100) (Y .
> > 200) (Z . 50))
> > (assoc 'y values) => (Y . 200)
> > (rplacd (assoc 'y values) 201) => (Y . 201)
> > In the first line, "values" is assigned a literal expression, and in
> > the last line, that literal expression is modified. Is this asking for
> > trouble?
>
> Yeah, I have noticed that myself. It's a disease. Every introductory
> text does the same (cheat a little to make examples more succinct),
> which is why a rite of passage for Lisp newbies is to emulate that
> example and be excoriated on c.l.l. for modifying a literal. :)
I think even the CLHS talks about the evil of doing that.
Somehow I think the problem is caused by too much literal mindedness.
Is there such a thing as metaphoric programming?
--
An ideal world is left as an excercise to the reader.
--- Paul Graham, On Lisp 8.1
Johnny wrote:
> Example under "assoc" :
>
> (setq values '((x . 100) (y . 200) (z . 50))) => ((X . 100) (Y .
> 200) (Z . 50))
> (assoc 'y values) => (Y . 200)
> (rplacd (assoc 'y values) 201) => (Y . 201)
>
> In the first line, "values" is assigned a literal expression, and in
> the last line, that literal expression is modified. Is this asking for
> trouble?
Yes, but you should keep Section 1.4.3 in mind where they say that
"subsections whose names begin with the words ``Note'' or ``Notes'' or
``Example'' or ``Examples'' are provided for illustration purposes only,
and are not considered part of the standard."
Pascal
--
Tyler: "How's that working out for you?"
Jack: "Great."
Tyler: "Keep it up, then."