Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

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

Search the Archive

Re: Mixing optional parameters and options

  • To: mathgroup at smc.vnet.net
  • Subject: [mg116180] Re: Mixing optional parameters and options
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Fri, 4 Feb 2011 01:39:41 -0500 (EST)

Since your definition didn't start with Clear, I suspect that old  
definitions for f were still in effect.

Clear[f]
Options[f] = {bla -> True};
f[x_, y_: 11, OptionsPattern[]] := If[OptionValue[bla], x*y, y/x]

f[5]

55

f[7]

77

f[5, 7, bla -> False]

7/5

Bobby

On Thu, 03 Feb 2011 04:34:59 -0600, Peter Breitfeld <phbrf at t-online.de>  
wrote:

>
> To give a simpe example which, I hope, makes clear my issue:
> Suppose I define this (silly) example function:
>
>
> Options[f]={bla->True};
> f[x_,y_:11,OptionsPattern[]:=If[OptionValue[bla],x*y,y/x]
>
> Now:
> f[5]    ----> 55 (ok)
> f[5,7]  ----> 35 (ok)
>
> f[5,7,bla->False]  ----> 7/5 (ok)
> f[5,bla->False]    ----> 5*(bla->False)
>
> I expected the result 11/5
>
> The only way I found was to define f like this:
>
> f[{x_,y_:11},OptionsPattern[]]
>
> Can it be done without the curly braces?
>
> Thank you


-- 
DrMajorBob at yahoo.com


  • Prev by Date: Re: phase portraits
  • Next by Date: Re: Why this cannot be solved
  • Previous by thread: Re: Mixing optional parameters and options
  • Next by thread: Re: Mixing optional parameters and options