9

I am going through some of the items in "Modern Differential Geometry of Curves and Surfaces with Mathematica, Third Edition".

An example of the style used by these authors is:

piriform[a_, b_][t_] := {a (1 + Sin[t]), b Cos[t] (1 + Sin[t])}

ParametricPlot[Evaluate[piriform[1, 1][t]], {t, 0, 2 Pi}, AspectRatio -> Automatic]

Can someone please explain why they use piriform[a_, b_][t_] as opposed to piriform[a_, b_, t_]?

Is there some advantage to the authors' form over the latter form?

Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453
Amzoti
  • 1,065
  • 10
  • 19
  • 2
    In the first case (piriform[a_,b_][t_]), you define SubValues for the symbol piriform while in the second case (piriform[a_,b_,t_]) you define DownValues. BTW, you don't need the Evaluate here. – István Zachar Jan 10 '14 at 14:16
  • 3
    see http://mathematica.stackexchange.com/questions/544/how-do-you-set-attributes-on-subvalues/545#545 and this http://mathematica.stackexchange.com/questions/7999/define-parameterized-function – Nasser Jan 10 '14 at 14:19

1 Answers1

13

The form f[a_, b_][t_] allows you to conveniently use f[a, b] as if it were a function. For example, you can Map it over a list:

f[a_, b_][t_] := a^t + b

f[2, 3] /@ {4, 6, 8}
{19, 67, 259}

Please see Define parameterized function for details about this format and alternatives. See also What is the distinction between DownValues, UpValues, SubValues, and OwnValues? for notes about the specific evaluation of SubValues definitions.

Be aware that it is difficult to use Hold attributes for the additional parameters of a function written this way but one can emulate it to a degree. See for example:

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371