0
$\begingroup$

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. *)
$\endgroup$
  • 1
    $\begingroup$ reference.wolfram.com/language/ref/Default.html $\endgroup$ – egwene sedai Jan 23 at 15:18
  • $\begingroup$ @egwenesedai That does not help. $\endgroup$ – LBogaardt Jan 23 at 17:11
  • $\begingroup$ ok, noticed that this may not be a good option here. I would avoid Set and use the proved-to-be-working SetDelayed unless there's a strong reason for not using that. Found a possible duplicate here, notice that answer still uses :> (RuleDelayed) $\endgroup$ – egwene sedai Jan 23 at 18:39
  • $\begingroup$ Yes, that's a duplicate, thanks. Unfortunately, not a satisfying answer... $\endgroup$ – LBogaardt Jan 24 at 8:51