8

I have noticed a function defined as such:

 f[x_][y_] := expr;

How is the argument y in 2nd pair of brackets being used? What is the difference from defining a function this way:

 f[x_, y_] := expr;
spaceKnot
  • 383
  • 1
  • 8

1 Answers1

10

It allows partial function application. Observe how function test1 defined this way can be called with the first argument, resulting in the return of another function of the remaining argument. Function test2 does not, and simply returns unevaluated since no match to its pattern occurs.

Clear[test1,test2]

test1[x_][y_]:=x^y
test2[x_,y_]:=x^y

test1[2][3]
(* 8 *)

test2[2,3]
(* 8 *)

test1[2]
(* test1[2] *)

%[3]
(* 8 *)

test2[2]
(* test2[2] *)

%[3]
(* test2[2][3] *)
dionys
  • 4,321
  • 1
  • 19
  • 46
ciao
  • 25,774
  • 2
  • 58
  • 139
  • To state it explicitly, you can define something like test3 = test1[2], and then call test3 /@ Range[4] – Jason B. Nov 17 '15 at 12:11