Talk:Partial function application: Difference between revisions
Content added Content deleted
(→Is Lisp correct?: It uses &rest to accept a variable number of arguments.) |
|||
Line 108: | Line 108: | ||
Lisp may well have a way of doing this, but I don't think the present example shows it. --[[User:Paddy3118|Paddy3118]] 23:57, 14 April 2011 (UTC) |
Lisp may well have a way of doing this, but I don't think the present example shows it. --[[User:Paddy3118|Paddy3118]] 23:57, 14 April 2011 (UTC) |
||
: The current task only requires N = 2. The current ''partial'' uses ''&rest'' to accept a variable number of arguments. It can work when N > 2, but I never tested it until now. The next example shows N = 6 and N = 4. |
|||
: <lang lisp>CL-USER> (defun partial (func &rest args1) |
|||
(lambda (&rest args2) (apply func (append args1 args2)))) |
|||
PARTIAL |
|||
CL-USER> (defun take6 (a b c d e f) |
|||
(list f b d c a e)) |
|||
TAKE6 |
|||
CL-USER> (take6 11 22 33 44 55 66) |
|||
(66 22 44 33 11 55) |
|||
CL-USER> (defvar take2 (partial #'take6 11 22 33 44)) |
|||
TAKE2 |
|||
CL-USER> (funcall take2 55 66) |
|||
(66 22 44 33 11 55)</lang> |
|||
: --[[User:Kernigh|Kernigh]] 00:53, 15 April 2011 (UTC) |