Mercurial > hg > xemacs-beta
comparison 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 |
comparison
equal
deleted
inserted
replaced
5549:493c487cbc3f | 5550:b908c7265a2b |
---|---|
82 `(fset 'f '(lambda (x) x))' (the lambda cannot be byte-compiled; probably | 82 `(fset 'f '(lambda (x) x))' (the lambda cannot be byte-compiled; probably |
83 the programmer intended `#'', although leaving the lambda unquoted will | 83 the programmer intended `#'', although leaving the lambda unquoted will |
84 normally suffice), but in general is it the programmer's responsibility to | 84 normally suffice), but in general is it the programmer's responsibility to |
85 quote lambda expressions appropriately." | 85 quote lambda expressions appropriately." |
86 `(function (lambda ,@cdr))) | 86 `(function (lambda ,@cdr))) |
87 | |
88 ;; Partial application of functions (related to currying). XEmacs; closures | |
89 ;; aren't yet available to us as a language type, but they're not necessary | |
90 ;; for this function (nor indeed is CL's #'lexical-let). See also the | |
91 ;; compiler macro in cl-macs.el, which generates a call to #'make-byte-code | |
92 ;; at runtime, ensuring that partially applied functions are byte-compiled. | |
93 (defun apply-partially (function &rest args) | |
94 "Return a function that is a partial application of FUNCTION to ARGS. | |
95 ARGS is a list of the first N arguments to pass to FUNCTION. | |
96 The result is a new function which does the same as FUNCTION, except that | |
97 the first N arguments are fixed at the values with which this function | |
98 was called." | |
99 `(lambda (&rest args) (apply ',function ,@(mapcar 'quote-maybe args) args))) | |
87 | 100 |
88 ;; FSF 21.2 has various basic macros here. We don't because they're either | 101 ;; FSF 21.2 has various basic macros here. We don't because they're either |
89 ;; in cl*.el (which we dump and hence is always available) or built-in. | 102 ;; in cl*.el (which we dump and hence is always available) or built-in. |
90 | 103 |
91 ;; More powerful versions in cl.el. | 104 ;; More powerful versions in cl.el. |