Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: Mixing optional parameters and options
Replies: 4   Last Post: Feb 4, 2011 1:44 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
thomas

Posts: 45
Registered: 7/28/07
Re: Mixing optional parameters and options
Posted: Feb 4, 2011 1:38 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

See here for a solution to this problem, provided by Leonid Shifrin:

http://groups.google.com/group/comp.soft-sys.math.mathematica/browse_frm/thread/35ff6cf97d5019ec/df1b14a433eb2fa6?lnk=gst&q=Functions+with+variable+number#df1b14a433eb2fa6

thomas

On Feb 3, 11:34 am, Peter Breitfeld <ph...@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
> --
> _________________________________________________________________
> Peter Breitfeld, Bad Saulgau, Germany --http://www.pBreitfeld.de






Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2013. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.