Re: Passing default options to nested function call
- To: mathgroup at smc.vnet.net
- Subject: [mg94060] Re: Passing default options to nested function call
- From: Bill Rowe <readnews at sbcglobal.net>
- Date: Wed, 3 Dec 2008 05:45:32 -0500 (EST)
On 12/2/08 at 12:41 AM, stoneyb at gmail.com (Stoney Ballard) wrote:
>My original question still stands: Is it safe to assume that only
>the first value for an option will be used, when there's more than
>one value for that option in the list?
The answer almost certainly depends on how options are used in
the function code. My preferred way of using options in
functions I write look something like
func[x_,y_,opts__]:=
Module[{stuff},
setting = opt1/.{opts}/.Options[func];
...
The first application of ReplaceAll ensures any options
specified at the time of the function call are looked at first.
And if they exist, opt1 will be replaced with something that
cannot be affected by the rules returned by Options[func]. And
if no options are specified, the second application of
ReplaceAll ensures opt1 is given a value.
Per the documentation for ReplaceAll, the first rule that is
applicable is used and no further rules are used. So, my
approach could be done as
setting = opt1/.Join[{opts},Options[func]]
One other thing, I might do is use FilterRules to filter out non
applicable options. But mostly I use this when passing some of
the options to a built-in function my function calls.