On Mon, 4 Jul 2011 09:31:31 +0000 (UTC), Tamas Papp said:
Why do some CL library functions have :key arguments?
I am asking because I am working on some statistics functions, and the design choice came up. Specifically, I can write functions like
(defun quantiles (sequence quantiles &key (key #'identity)) ...)
but it is a bit cumbersome. I can make my code simpler by relying on calls like
(quantiles (map 'vector key vector) quantiles)
That approach doesn't work with many of the CL functions (e.g. find, delete, substitute, remove-duplicates) because they operate on (or return) the elements of the sequence, not the keys. The :key argument just affects the arguments to the :test function.