Re: &key and how it's used

Sam Steingold <[email protected]>
Newsgroups gmane.lisp.clisp.devel
Message-ID <[email protected]>
> * Yves S. Garret <[email protected]> [2012-06-17 14:20:13 -0400]:
>>
>  1) how *db* is accessed, that's where all the data is held and

(defun select (selector-fn)
  (remove-if-not selector-fn *db*))
 
(defun where (&key title artist rating (ripped nil ripped-p))
  #'(lambda (cd)
    (and
      (if title    (equal (getf cd :title)  title)  t) 
      (if artist   (equal (getf cd :artist) artist) t)
      (if rating   (equal (getf cd :rating) rating) t)
      (if ripped-p (equal (getf cd :ripped) ripped) t))))

SELECT returns elements of *DB* which satisfy SELECTOR-FN
WHERE returns a function which __APPARENTLY__ can be used as an argument
to SELECT.
e.g.,
(select (where :title "foo"))
will return the objects with the given title.


> 2) what the heck is &key?

a lambda list keyword.
http://www.lispworks.com/documentation/HyperSpec/Body/03_da.htm

it is a way to pass optional arguments to functions in a position
independent way.
e.g.:

(defun foo (&key (a 1) (b 2) (c 3))
  (list a b c))

(foo :b 10) => (1 10 3)
(foo :a 4 :c 5) => (4 2 5)
(foo :c 5 :a 4) => (4 2 5)

> If I'm missing something absurdly obvious, please feel free to point it out.

You might get a more detailed and informative reply to such a general
Lisp question on the comp.lang.lisp newsgroup.

-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000
http://www.childpsy.net/ http://jihadwatch.org http://openvotingconsortium.org
http://iris.org.il http://palestinefacts.org http://mideasttruth.com
Democrats, get out of my wallet! Republicans, get out of my bedroom!

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
clisp-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/clisp-devel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.