2009/6/4 Nikodemus Siivola nikodemus@random-state.net:
What about papply or partial-apply? Or maybe p-apply? This way, The reversed version might be called rp-apply. Otherwise reverse-partial-apply?
I am aware that this is a common usage/mistake in CL, but Alexandria doesn't have to perpetuate this error. An unfortunate downside is breaking backwards compatibility. I'm not sure what Alexandria's policy is regarding this...
I'm happy to send patches if this renaming is agreed upon.
I'm not sure. I'm not totally opposed, but I'm not convinced either: even if it wrong, the names are "culturally correct", if you will. Names partial-apply and partial-reverse-apply would be my preferred ones if we did the renaming.
I'm slowly coming to think that calling them CURRY and RCURRY is indeed a mistake we should stop propagating.
(defun partial-apply (function &rest partial-arguments) "Returns a function that calls FUNCTION with PARTIAL-ARGUMENTS followed by the arguments it is called with." (declare (optimize (speed 3) (safety 1) (debug 1))) (let ((fn (ensure-function function))) (lambda (&rest more) (declare (dynamic-extent more)) ;; Using M-V-C we don't need to append the arguments. (multiple-value-call fn (values-list partial-arguments) (values-list more)))))
(define-compiler-macro partial-apply (function &rest partial-arguments) (let ((temps (make-gensym-list (length partial-arguments) "PARTIAL-ARG"))) `(let ,(mapcar #'list temps partial-arguments) (declare (optimize (speed 3) (safety 1) (debug 1))) (lambda (&rest more) (declare (dynamic-extent more)) (apply ,function ,@temps more)))))
(defun reverse-partial-apply (function &rest partial-arguments) "Returns a function that calls FUNCTION with the arguments it is called with followed by PARTIAL-ARGUMENTS." (declare (optimize (speed 3) (safety 1) (debug 1))) (let ((fn (ensure-function function))) (lambda (&rest more) (declare (dynamic-extent more)) (multiple-value-call fn (values-list more) (values-list partial-arguments)))))
Cheers,
-- Nikodemus