Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #15865

Mixing optional parameters and options

From Peter Breitfeld <phbrf@t-online.de>
Newsgroups comp.soft-sys.math.mathematica
Subject Mixing optional parameters and options
Date 2011-02-03 10:34 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <iie0bv$bt3$1@smc.vnet.net> (permalink)

Show all headers | View raw


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

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Mixing optional parameters and options Peter Breitfeld <phbrf@t-online.de> - 2011-02-03 10:34 +0000

csiph-web