Mercurial > hg > xemacs-beta
diff lisp/subr.el @ 5550:b908c7265a2b
Add the #'apply-partially API, as used by GNU.
lisp/ChangeLog addition:
2011-08-12 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el:
* cl-macs.el (apply-partially): New compiler macro.
* subr.el:
* subr.el (apply-partially): New.
Sync this function's API and docstring from GNU. The
implementation is mine and trivial; the compiler macro in
cl-macs.el ensures that partially-applied functions in compiled
code are also compiled.
tests/ChangeLog addition:
2011-08-12 Aidan Kehoe <kehoea@parhasard.net>
* automated/lisp-tests.el:
Trivial tests of #'apply-partially, just added to subr.el.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Fri, 12 Aug 2011 16:02:30 +0100 |
parents | 544e6336d37c |
children | 5e256f495401 |
line wrap: on
line diff
--- a/lisp/subr.el Wed Aug 10 16:50:37 2011 +0100 +++ b/lisp/subr.el Fri Aug 12 16:02:30 2011 +0100 @@ -85,6 +85,19 @@ quote lambda expressions appropriately." `(function (lambda ,@cdr))) +;; Partial application of functions (related to currying). XEmacs; closures +;; aren't yet available to us as a language type, but they're not necessary +;; for this function (nor indeed is CL's #'lexical-let). See also the +;; compiler macro in cl-macs.el, which generates a call to #'make-byte-code +;; at runtime, ensuring that partially applied functions are byte-compiled. +(defun apply-partially (function &rest args) + "Return a function that is a partial application of FUNCTION to ARGS. +ARGS is a list of the first N arguments to pass to FUNCTION. +The result is a new function which does the same as FUNCTION, except that +the first N arguments are fixed at the values with which this function +was called." + `(lambda (&rest args) (apply ',function ,@(mapcar 'quote-maybe args) args))) + ;; FSF 21.2 has various basic macros here. We don't because they're either ;; in cl*.el (which we dump and hence is always available) or built-in.