I doubt that this is possible natively (although I'd be happy to be corrected on that and will delete my answer in that case). You can sort of roll your own, with a bunch of definitions of f
:
Clear[f, dflt];
f[dflt, b_, c_, d_, e_] := f[1, b, c, d, e]
f[a_, dflt, c_, d_, e_] := f[a, 2, c, d, e]
f[a_, b_, dflt, d_, e_] := f[a, b, 3, d, e]
f[a_, b_, c_, dflt, e_] := f[a, b, c, 4, e]
f[a_, b_, c_, d_, dflt] := f[a, b, c, d, 5]
f[a_, b_, c_, d_, e_] := a + b + c + d + e
f[7, 8, dflt, 9, 10]
(* 37 *)
7 + 8 + 3 + 9 + 10
(* 37 *)
This is only meant as a starting point.
One can generate these automatically from a given pattern and definition. Doing so in a completely general way might be quite an undertaking, but here is a solution which at least works if all patterns are simple Blank
s and they all have a default value:
ClearAll[dflt, generateDefaults]
SetAttributes[generateDefaults, HoldAll]
generateDefaults[pattern_, result_] :=
Module[{head = Head@pattern, args = List @@ pattern, defs, vals},
defs = head @@ (args /. Verbatim@# -> dflt) & /@ args;
vals = head @@ (args[[All, 1, 1]] /. #[[1, 1]] -> Last@#) & /@ args;
MapThread[SetDelayed, {defs, vals}];
pattern := result
]
This will also set default values on the individual definitions, such that omitting elements from the end also works.
As the answers on the duplicate mention, instead of dflt
you could use Null
which would allow you to omit the argument altogether and call the function like
f[7, 8, , 9, 10]