views:

128

answers:

5

In a functional programming what would you call this sort of operation?

function(f,vargs){ //variable count of arguments
   return function(){
       return f(vargs)
   }
}

I think this is Currying, but I had the impression that currying is the term when we bind a single argument not several arguments. Or perhaps this is a delay, not really sure...

+1  A: 

I would call is constructing a closure.

cletus
+4  A: 

I think it's called function application.

Remember that in a functional paradigm,

function(){
    return f(vargs)
}

being a function with no arguments, is roughly the equivalent of a procedural-programming variable containing the result of f(vargs).

Artelius
+2  A: 

I am of the understanding that currying is the act of partially applying functions and returning a function that matches the signature of the original function minus the applied arguments.

Take a look at this article - The Art of Currying

This looks like a Higher Order function

Russ Cam
Yeah I'm not sure if it's one argument at a time or not.
Robert Gould
I don't think that it has to be one argument to be a curried function, just not all arguments :)
Russ Cam
+4  A: 

apply is the correct term -- for instance, Python had an equivalent apply (that is now deprecated).

See also partial application in Haskell or in Javascript. If partial application uses some of the arguments of the function, then it follows that full application, or just application, must use all of the arguments, like you did above.

Mark Rushakoff
Good deduction work there, thanks!
Robert Gould
A: 
function(f, args) {
    return (
        function() { return f(vargs) }
      )
 }

The outer function takes f and args, what it returns is an anonymous function that only returns f(args), where f and vargs are arguments of the outer function.

In Mathematica for example you can write it as F[f_, args___] := f[args]& . Because the returned anonymous function is a constant function (not accepting any argument), you may also write it as F[f_, args___] := f[args], omitting the last &.

Jetcheng Chu
Do you know the name used in Mathematica for this sort of thing?
Robert Gould
To my knowledge there is no standard name for the whole operation, which takes _f_ and _args_ as arguments, and returns a constant function whose value is obtained by applying _f_ to _args_.
Jetcheng Chu