Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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;
share|improve this question
1  
It allows you to work with and pass around f[something] as a separate object. You could for example Map it easily. See for example this question and the two answers: one uses subvalues ("double bracket") and the other uses downvalues (a single bracket) to achieve the same thing. The downvalues version needs to create new symbol names with extra definitions for each instance of the structure it's generating. The subvalues version doesn't. –  Szabolcs Dec 31 '13 at 4:04
1  

1 Answer 1

up vote 5 down vote accepted

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]
test2[2,3]

test1[2]
%[3]

test2[2]
%[3]

Out[2093]= 8
Out[2094]= 8
Out[2095]= test1[2]
Out[2096]= 8
Out[2097]= test2[2]
Out[2098]= test2[2][3]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.