I want to do something like
foo[OptionsPattern[]] := OptionValue[b]
Options[foo] = {a -> 0, b :> OptionValue[a]};
foo[a -> 1]
and have Mathematica give me 1
, instead of 0
. Is there a better way to do this than
foo[OptionsPattern[]] := (
Options[foo] = {a -> 0, b :> OptionValue[a]};
OptionValue[b]
)
foo[a -> 1]
?
For one thing, it's inefficient to set the options of foo
on every call, especially if foo
has many options.
This is why we have
Automatic
. I'd use something like:Plus this allows for more complicated interpretation of automatic values if you need it.