MathGroup Archive 1995

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

Search the Archive

Re: Function parameters, using : and ?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg2836] Re: [mg2813] Function parameters, using : and ?
  • From: brucec (Bruce Carpenter)
  • Date: Sat, 23 Dec 1995 03:19:16 -0500

>Hi!  Is there a way of using the default pattern(:) and the match(?)
>pattern for the same argument in a function?  I'm interested in writting
>something like this
>
>   Func[x_List, y_List, epsilon_(?NumberQ):10^-6] := Module[{},...]
>
>but I can't get it to work.  What is the problem? I must have tried all
>the different combinations of the charaters _?: without success.  Any
>suggestions?
>
>- Ricardo Marimon
>  rmarimon at leland.stanford.edu

I've run into this before too.  The way I handle it is with the pattern /;
condition rather than pattern ? test.

In[1]:=
Func[x_List, y_List, epsilon_:10^-6] :=
      Module[{},{x, y, epsilon}] /; NumberQ[epsilon]
In[2]:=
Func[{1,2,3},{a,b,c}]
Out[2]=
                          1
{{1, 2, 3}, {a, b, c}, -------}
                       1000000
In[3]:=
Func[{1,2,3},{a,b,c}, 33]
Out[3]=
{{1, 2, 3}, {a, b, c}, 33}
In[4]:=
Func[{1,2,3},{a,b,c}, d]
Out[4]=
Func[{1, 2, 3}, {a, b, c}, d]

Note that you can't put the condition inside with the default value either.

Cheers,

Bruce Carpenter




  • Prev by Date: Re: How to combine two graphs with different scales?
  • Next by Date: Mathematica for Students now available for Linux
  • Previous by thread: Re: Function parameters, using : and ?
  • Next by thread: Mathlink & Macintosh & CodeWarrior