This is the code in Mathematica:
h[x_] := (If[x > 5, Return[big]]; t = x^3; Return[t - 7])
I fully understand what the code does, with h[4]=4^3-7=57
and h[6]=h[7]=big
but I have the following issues:
h[x_]
does not function if I remove the brackets()
ieh[x_]If[x > 5, Return[big]]; t = x^3; Return[t - 7]
, what is the function of()
in the code?- Can someone also explain the significance of the semi-colons in this code, and what is it used instead of commas (which make the code not work). What are the benefits of using ; instead of , in code?
t
in there which can be problematic if you're usingt
somewhere else. Tryh[x_] := Block[{t}, If[x > 5, big, t = x^3; t - 7]]
(but even that is not the best way to do it). Also, look upCompoundExpression[]
. $\endgroup$ – J. M. will be back soon♦ Oct 14 '18 at 18:18()
the function definition would end at the first semicolon. With the()
the function definition is the whole line. TheIf[]
tests x and potentially bails out with the value big. If it doesn't bail out then thet=x^3;Return[t-7]
is all done. Be cautious withReturn
because people have reported problems with that. $\endgroup$ – Bill Oct 14 '18 at 18:21