MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Passing default options to nested function call

  • To: mathgroup at smc.vnet.net
  • Subject: [mg94016] Re: Passing default options to nested function call
  • From: Stoney Ballard <stoneyb at gmail.com>
  • Date: Tue, 2 Dec 2008 00:41:11 -0500 (EST)
  • References: <10132325.1227952316551.JavaMail.root@m02> <ggtv8o$7fv$1@smc.vnet.net>

That was over-abstracted, I guess. I'm trying to pass things like
Graphics options to a nested call to Graphics, so I don't want to
rename the options, just pass on only the ones that apply to the
nested call.

What I really do is something like this:

  Options[fun1] = Join[{opt1 -> 1},Options[Graphics]]

so that

  fun1[opts:OptionsPattern[]]

doesn't complain if I supply Graphics options to fun1.

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?

If not, then it seems that I'd have to do:
  DeleteDuplicates[opts, First[#1] == First[#2] &]
which is unappealing if it's unnecessary.

 - Stoney

On Nov 30, 7:00 am, "David Park" <djmp... at comcast.net> wrote:
> That seems all very strange to me. If you are going to have one function
> nested within another and pass options, then you need distinct names for =
the
> options. If you have the same option name 'opt2' for both functions then =
you
> must expect some kind of restrictive behavior. For example, I don't see h=
ow
> you could pass different opt2 values to the two routines.
>
> So why not use something like this:
>
> Options[fun2] = {opt3 -> 3};
> fun2[OptionsPattern[]] := OptionValue[opt3]
>
> fun2[]
> fun2[opt3 -> 25]
> 3
> 25
>
> Options[fun1] = Join[{opt1 -> 1, opt2 -> 2}, Options[fun2]];
> fun1[opts : OptionsPattern[]] := {OptionValue[opt1],
>   fun2[FilterRules[{opts}, Options[fun2]]]}
>
> fun1[]
> fun1[opt1 -> 20, opt3 -> 25]
>
> {1, 3}
> {20, 25}
>
> David Park


  • Prev by Date: Re: Quick help needed very much!!!!
  • Next by Date: Re: Re: Comment display style?
  • Previous by thread: Re: ImageCrop/ImageRotate
  • Next by thread: Re: Passing default options to nested function call