Subject: Re: Question about PG's ACL
From: rpw3@rpw3.org (Rob Warnock)
Date: Wed, 04 May 2005 03:19:21 -0500
Newsgroups: comp.lang.lisp
Message-ID: <w6Gdnd4jxLMUGOXfRVn-qw@speakeasy.net>
Kenny Tilton  <ktilton@nyc.rr.com> wrote:
+---------------
| wildwood wrote:
| > My question is, what would the "usual meanings and defaults" be for
| > :key and :test? 
| 
| key is a function applied to each candidate to return the object 
| actually to be compared with the one being sought. So the default is 
| IDENTITY. If you wanted to find a string of a certain length, you could 
| write: (find 42 strings :key 'length).
| 
| test is the function used to compare the values. eql is the default.
| if  you were searching a list of strings: (find "42" strings :test 
| 'string-equal)
+---------------

And if you wanted to find the first string of at *least* a certain
length, you could combine both keywords and write:

	> (let ((strings '("foo" "bar" "blather" "gorp" "bleep")))
	    (find 4 strings :key 'length :test '<= ))

        "blather"
	> 

Finally, as an example of gross abuse of the :TEST facility, I once
used the following when I was too lazy to write a tree walker:  ;-}  ;-}

	> (defun process-leaf (x y)
	    (declare (ignore y))
	    (when x
	      (format t "Leaf = ~s~%" x)) ; or some more complex processing
	    t)

	PROCESS-LEAF
	> (let ((tree '(a b (c ((d e) f) g (h . i) j))))
	    (tree-equal tree tree :test #'process-leaf))
	Leaf = A
	Leaf = B
	Leaf = C
	Leaf = D
	Leaf = E
	Leaf = F
	Leaf = G
	Leaf = H
	Leaf = I
	Leaf = J
	T
	> 


-Rob

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607