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

MathGroup Archive 2011

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

Search the Archive

Mixing optional parameters and options

  • To: mathgroup at smc.vnet.net
  • Subject: [mg116164] Mixing optional parameters and options
  • From: Peter Breitfeld <phbrf at t-online.de>
  • Date: Thu, 3 Feb 2011 05:34:59 -0500 (EST)

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
-- 
_________________________________________________________________
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de


  • Prev by Date: Why this cannot be solved
  • Next by Date: Re: it isn't strange?!
  • Previous by thread: Re: Why this cannot be solved
  • Next by thread: Re: Mixing optional parameters and options