Tamas Papp
2011-07-04 09:31:31 UTC
Content preview: 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)) ...) [...]
Content analysis details: (-2.3 points, 5.0 required)
pts rule name description
---- ---------------------- --------------------------------------------------
0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider
(tkpapp[at]gmail.com)
-2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium
trust
[80.91.229.12 listed in list.dnswl.org]
-0.0 SPF_HELO_PASS SPF: HELO matches SPF record
-0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay
domain
-0.0 SPF_PASS SPF: sender matches SPF record
0.0 T_TO_NO_BRKTS_FREEMAIL To: misformatted and free email service
Archived-At: <http://permalink.gmane.org/gmane.lisp.cl-pro/485>
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. Not a major concern at the moment, but if it
ever becomes one, I could just define a compiler macro to take care of
forms like this and transform to something like
(quantile-with-keys vector quantiles key)
I also thought of defining something like
(defgeneric map1 (function object)
(:method (function (list list))
(mapcar function list))
...)
for the sole purpose of mapping objects to similar objects (eg lists to
lists, arrays to arrays, etc) and allow it to be optimized away (like
above) by compiler macros.
I would appreciate advice on this. I am especially interested in the
reason why some CL functions have :key arguments: is it because of
efficiency, backward-compatibility/history, or something else?
Thanks,
Tamas
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)) ...) [...]
Content analysis details: (-2.3 points, 5.0 required)
pts rule name description
---- ---------------------- --------------------------------------------------
0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider
(tkpapp[at]gmail.com)
-2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium
trust
[80.91.229.12 listed in list.dnswl.org]
-0.0 SPF_HELO_PASS SPF: HELO matches SPF record
-0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay
domain
-0.0 SPF_PASS SPF: sender matches SPF record
0.0 T_TO_NO_BRKTS_FREEMAIL To: misformatted and free email service
Archived-At: <http://permalink.gmane.org/gmane.lisp.cl-pro/485>
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. Not a major concern at the moment, but if it
ever becomes one, I could just define a compiler macro to take care of
forms like this and transform to something like
(quantile-with-keys vector quantiles key)
I also thought of defining something like
(defgeneric map1 (function object)
(:method (function (list list))
(mapcar function list))
...)
for the sole purpose of mapping objects to similar objects (eg lists to
lists, arrays to arrays, etc) and allow it to be optimized away (like
above) by compiler macros.
I would appreciate advice on this. I am especially interested in the
reason why some CL functions have :key arguments: is it because of
efficiency, backward-compatibility/history, or something else?
Thanks,
Tamas