MathGroup Archive 2005

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

Search the Archive

Re: Problem with MatchQ and SameQ

  • To: mathgroup at smc.vnet.net
  • Subject: [mg56444] Re: [mg56429] Problem with MatchQ and SameQ
  • From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
  • Date: Tue, 26 Apr 2005 01:32:44 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

 

>-----Original Message-----
>From: Miguel [mailto:mbli at euskalnet.net] 
To: mathgroup at smc.vnet.net
>Sent: Monday, April 25, 2005 7:31 AM
>Subject: [mg56444] [mg56429] Problem with MatchQ and SameQ
>
>Hi,
>Normally I operate with Mathematica 5.0. The functions MatchQ and
>SameQ work well  in a notebook but don't it in a programm.
>
>For example,in a notebook
>Clear[f];
>In[1]: f[x_,y_,option_]:=
>  If[MatchQ[option,SolutionForm->Explicit],x+y,
>    If[MatchQ[option,SolutionForm->Implicit],x*y],Print["Eror"]]
>
>In[2]:
>f[2,3,SolutionForm->Implicit]
>Out[2]:
>6
>It works well.
>
>In my programm,
>
><<Calculus`MyProgramm`
>In[3]:
>f[2,3,SolutionForm->Implicit]
>Out[2]:
>Error
>
>Thanks
>
>

Miguel,

you are looking at the wrong place! MatchQ and SameQ won't account for
that, more probably ProgamU.

I guess your problem lies with your package (which you did not show): I
suppose, there you do use local definitions for Implicit, Explicit, yet
when you call the function, globals. (You have to define them outside of
the private part of your package; look into a standard package for an
example.)


BTW: The standard idiom for recognizing Options is this:

f[x_, y_, options___] := Module[{sForm},
    sForm = SolutionForm /. Flatten[{options}];
    Switch[sForm, Explicit, x + y,
      Implicit, x*y,
      _, Print["Missing Option SolutionForm"]]]

This is much more robust.


Also: consider defining default options for f (consult the book).


--
Hartmut Wolf


  • Prev by Date: Re: Re: to those interested in * finding * Mathematica help
  • Next by Date: Re: Shell script and Mathematica.
  • Previous by thread: Problem with MatchQ and SameQ
  • Next by thread: Re: Problem with MatchQ and SameQ