LISP: Keyword parameters, supplied-p
Posted
by echox
on Stack Overflow
See other posts from Stack Overflow
or by echox
Published on 2010-04-29T09:12:16Z
Indexed on
2010/04/29
9:17 UTC
Read the original article
Hit count: 431
common-lisp
|lisp
At the moment I'm working through "Practical Common Lisp" from Peter Seibel.
In the chapter "Practical: A Simple Database" (http://www.gigamonkeys.com/book/practical-a-simple-database.html) Seibel explains keyword parameters and the usage of a supplied-parameter with the following example:
(defun foo (&key a (b 20) (c 30 c-p)) (list a b c c-p))
Results:
(foo :a 1 :b 2 :c 3) ==> (1 2 3 T)
(foo :c 3 :b 2 :a 1) ==> (1 2 3 T)
(foo :a 1 :c 3) ==> (1 20 3 T)
(foo) ==> (NIL 20 30 NIL)
So if I use &key at the beginning of my parameter list, I have the possibility to use a list of 3 parameters name, default value and the third if the parameter as been supplied or not. Ok. But looking at the code in the above example:
(list a b c c-p)
How does the lisp interpreter know that c-p is my "supplied parameter"?
© Stack Overflow or respective owner