Re: novice: mapcan use?
- From: Pascal Costanza <pc@xxxxxxxxx>
- Date: Sun, 28 Aug 2005 22:33:24 +0200
Bernd Schmitt wrote:
Ok, I will do so (even if I do not understand the difference between '(1 2) and (list 1 2) right now).
All programming languages have literal values. It's so common that it's hard to understand why that's something special. But it really is.
For example, when you bind 42 to a variable, the "42" is a value that you have literally written as part of your source code:
(setq x 42)
Whereas when you increment x afterwards you will have a number stored in x that you have never written down:
(setq x (+ x 1)) x => 43
The latter output ("42") was not part of your program source code.Lisp is special in many ways, including the fact that anything can be made part of some source code (as Kent already explained). When you type in '(1 2), the parser (called reader in Lisp terminology) parses the list consisting of the elements 1 and 2, and makes it part of your source code. The quote ("'") takes care that this will be treated as a literal datum in your program.
Now think about it: Assume you would change the contents of that list at runtime - this would theoretically mean that you would change the source code, since that list is part of that source code! That doesn't make sense, so ANSI Common Lisp states that the result is undefined when you try to do this.
On the other hand, list is a function that takes some elements and creates a list at runtime. Since that list is not part of some source code, it is perfectly legal to change its contents. So, as an analogue, (setq l '(1 2)) is similar to (setq x 42) whereas (setq l (list 1 2)) is similar to (setq x (+ x 1)), that is, the former value is taken from the source code whereas the latter value is generated at runtime.
I hope this helps.
Pascal
-- OOPSLA'05 tutorial on generic functions & the CLOS Metaobject Protocol ++++ see http://p-cos.net/oopsla05-tutorial.html for more details ++++ .
- Follow-Ups:
- Re: novice: mapcan use?
- From: Bernd Schmitt
- Re: novice: mapcan use?
- References:
- novice: mapcan use?
- From: Bernd Schmitt
- Re: novice: mapcan use?
- From: Pascal Costanza
- Re: novice: mapcan use?
- From: Bernd Schmitt
- Re: novice: mapcan use?
- From: Pascal Costanza
- Re: novice: mapcan use?
- From: Bernd Schmitt
- novice: mapcan use?
- Prev by Date: Re: novice: mapcan use?
- Next by Date: Re: novice: mapcan use?
- Previous by thread: Re: novice: mapcan use?
- Next by thread: Re: novice: mapcan use?
- Index(es):
Relevant Pages
|
|