0

Optional arguments can be defined in SetDelayed (:=) Functions (see f1 below and here and here). However, how can one accomplish this in Set (=) Functions (see f2 and f3 below)?

f1[x_:0]:=x
f1[4] (* 4 *)
f1[] (* 0 *)
f2=Function[{x},x]
f2[4] (* 4 *)
f2[] (* Function:fpct:Too many parameters in {x} to be filled from Function[{x},x][]. *)
f3=Function[{x:0},x] (* Function:flpar:Parameter specification {x:0} in Function[{x:0},x] should be a symbol or a list of symbols. *)
LBogaardt
  • 1,595
  • 1
  • 11
  • 21

0 Answers0