:Keywords and their use

Discussion of Common Lisp

:Keywords and their use

Postby webguy08 » Wed Jan 13, 2010 6:22 pm

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?
webguy08
 
Posts: 14
Joined: Sat Jan 02, 2010 4:11 pm

Re: :Keywords and their use

Postby nuntius » Wed Jan 13, 2010 8:02 pm

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
User avatar
nuntius
 
Posts: 498
Joined: Sat Aug 09, 2008 10:44 am
Location: Burlington, MA

Re: :Keywords and their use

Postby webguy08 » Thu Jan 14, 2010 6:00 am

Aaah I see. That second article explains it well :). However, how was I supposed to know that the keyword had to be :TEST?
webguy08
 
Posts: 14
Joined: Sat Jan 02, 2010 4:11 pm

Re: :Keywords and their use

Postby Ramarren » Thu Jan 14, 2010 6:16 am

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/HyperSpec/Front/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.
Ramarren
 
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland


Return to Common Lisp

Who is online

Users browsing this forum: No registered users and 5 guests

cron