-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Am 04.07.2011 11:31, schrieb Tamas Papp:
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)
but this conses a bit more.
Doesn't quantiles just pass the key to sort? Is there some smarter algorithm I am not aware of right now?
Also, passing the key lets you return the complete objects (or whatever), not just the keys as in the map call. For example, compare
(quantiles #((a 1) (b 4) (c 2) (d 2) (e 5)) 2 :key #'second)
with
(quantiles (map 'vector #'second #((a 1) (b 4) (c 2) (d 2) (e 5))) 2)
In the first case, you could return (d 2), but not in the second.
Maybe I'm just missing the point. :)
Best wishes,
Svante
- -- Svante Carl v. Erichsen Wentorfer Str. 96 21029 Hamburg
+49-(0)40-34923721 +49-(0)160-6941474 Svante.v.Erichsen@web.de