Trying to map OptionValue to a list of option names doesn't work.
options = {opt1, opt2, opt3};
Options[f] = # -> True & /@ options;
f[x_, o:OptionsPattern[]] := OptionValue /@ options;
f[x_] := f[x, Sequence@{}];
Executing
f[1, opt1 -> False]
gives the result
{OptionValue[opt1], OptionValue[opt2], OptionValue[opt3]}
instead of the expected
{False, True, True}
Why does this happen with OptionValue and can it be fixed?
f[x_, o : OptionsPattern[]] := Evaluate[OptionValue /@ options];instead – Dr. belisarius Feb 16 '14 at 23:53f[x_, o : OptionsPattern[]] := OptionValue[#] & /@ options;. For an explanation, read this discussion. – Leonid Shifrin Feb 16 '14 at 23:56user:81 "OptionValue" magicalas soon as I saw the title :) – rm -rf Feb 17 '14 at 00:00