Bug introduced in 8.0 or earlier and fixed in 11.0.0
Case number: 305932.
In the front-end notebook (Mathematica 9.0 and 10.2):
g[x: Optional[_,default]]:=x;
has no problems, and works correctly (g[]
outputs default
, and g[1]
outputs 1
).
However, when the following package is constructed in an .m
file called Dummy.m
:
BeginPackage["Dummy`"];
f
g; Thing;
Begin["`Private`"];
g[x: Optional[_,default]]:=x; (*Minimal case causing problem*)
f[x: Optional[Thing->{_},Thing->{1}]]:=x; (*I need this in my package*)
End[];
EndPackage[];
The same line of code throws a General::patop
error upon package initialization. (The definition for f
is the structure of the optional argument I need to achieve in my package.)
<<Dummy`
Is this a bug? and I can I define f
in my package?
x
inside theOptional
like so:g[Optional[x: _,default]]
. However, the fact that the former syntax doesn't throw an error in the front-end but does when called from within a package seems a bit strange... $\endgroup$:
is actually shorthand notation forOptional
. This meansx:Optiona[...]
isOptional[x,Optional[_,default]]
. The way to specify this is withf[x_:default]:=x
$\endgroup$:
denotes pattern name... $\endgroup$