Page 1 of 1

:Keywords and their use

Posted: Wed Jan 13, 2010 6:22 pm
by webguy08
Hi all,

I'm struggling to understand the use of keywords. I understand that keywords evaluate to themselves, thus :A is :A. But take the following code:

Code: Select all

(member '(c cat) '((b bird) (c cat) (d dog) (s squirrel)))
If I were to run that, it would return NIL because member is using eql instead of equal (I think), thus if I write:

Code: Select all

(member '(c cat) '((b bird) (c cat) (d dog) (s squirrel)) :TEST #'EQUAL)
It will return the list, as it should. However, I do not understand why you have to use :TEST. How do you know what to name these keywords, and what is their use?

Re: :Keywords and their use

Posted: Wed Jan 13, 2010 8:02 pm
by nuntius
Those are known as "keyword parameters"; they are part of the function prototype.
http://www.lispworks.com/documentation/ ... 03_dad.htm
http://gigamonkeys.com/book/functions.html

Re: :Keywords and their use

Posted: Thu Jan 14, 2010 6:00 am
by webguy08
Aaah I see. That second article explains it well :). However, how was I supposed to know that the keyword had to be :TEST?

Re: :Keywords and their use

Posted: Thu Jan 14, 2010 6:16 am
by ramarren
My previous posts contained many links to the Hyperspec, but to restate explicitly...

There exists such a concept as technical documentation. It is a body of text which explains in a, hopefully, systematic, exhaustive and detailed manner how a system woks and how you are supposed to use it.

For Common Lisp the most important piece of technical documentation is the ANSI standard. There is an online hyperlinked version available at http://www.lispworks.com/documentation/ ... /index.htm. The contents are grouped by chapters, and there is an index. Using either you can find documentation for function MEMBER, which, among other this, lists all the arguments the function takes, what type they should be and what they do.