If I define, for example,
f[OptionsPattern[{}]] := OptionValue[a]
Then the output for f[a -> 1]
is 1.
However, in my code, I have a function that must be called using the syntax f[some parameters][some other parameters]
, and I want to add options to the second set of square brackets. So I tried:
g[][OptionsPattern[{}]] := OptionValue[a]
But then, the output for g[][a -> 1]
is OptionValue[a]
instead of 1. I'm not sure why this is not working. Shouldn't OptionsPattern[{}]
match any set of options, no matter where they are located?
How can I add options that can be provided in the second set of square brackets instead of the first?
g[OptionsPattern[{}]] := OptionValue[a]
and theng[][a -> 1]
"works". I think it is generally advised to stay clear ofSubValues
(whichg[x][y]
implies). Is it possible to refactor the function? $\endgroup$OptionsPattern[]
? $\endgroup$SubValues
? $\endgroup$SubValues
have a look at Section 2.2.5 Composite variables and SubValues of Leonid Shifrin's excellent book. $\endgroup$