- Code: Select all
(defun functional (this-function &rest other-functions)
(lambda (&rest closure-args)
(apply this-function (mapcar (rcurry #'apply closure-args) other-functions))))
(I used Graham's rcurry (ANSI Common Lisp page 110) to partially apply the argument list, because it seemed like the quickest way of mapcar-ing a function using the same arguments each time. Probably I am missing an obvious way to do it, but it isn't my primary concern at the moment.)
The idea is you have a number of other-functions that take the same kind of arguments. Let's say you want to call these functions on the same args and pass all of the results to another function, this-function, as a test or an aggragation or something. And let's say you want to pass around this prepackaged test/aggragator and use it whereever you want. So that instead of saying (this-function ((function1 myargs) (function2 myargs) [...]) every time you use it, you simply create a new function with (functional this-function function1 function2 [...]), then pass the resulting closure whatever args you wish. I think it has a lot of potential, at least for my pet project, but it'd be much nicer if it worked with special operators and/or macros. I'm talking primarily about this-function, though it'd be cool if other-functions could be special ops or macros as well.