MathGroup Archive 1999

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

Search the Archive

Re: ReplaceAll in If Statement

  • To: mathgroup at
  • Subject: [mg19480] Re: ReplaceAll in If Statement
  • From: paulh at (P.J. Hinton)
  • Date: Sat, 28 Aug 1999 15:53:08 -0400
  • Organization: "Wolfram Research, Inc."
  • References: <7q20sl$>
  • Sender: owner-wri-mathgroup at

In article <7q20sl$q9i at>, "Tom Compton" <comptont at> writes:

>In the following sequence I expected z to evaluate to 1 in the
>Module.  It appears that the test in the module does not
>evaluate to either True or False.  I don't understand why.
>Can anyone explain?
>If[a /. {opts}, z=1, z=2, z=3];
>{a, z} /. {opts}]

The fail case happens because your True is wrapped within a List.

In[1]:= opList={a->True} 

Out[1]= {a -> True}

In[2]:= test[opts___]:=Module[{}, a /. {opts}]

In[3]:= test[opList]

Out[3]= {True}

Pulling out the True from the list should fix the problem.

In[4]:= test[opts___]:=Module[{},
          If[First[a /. {opts}],  z=1, z=2, z=3];
            {a, z} /. {opts}]

In[5]:= test[opList]

Out[5]= {{True, 1}}

P.J. Hinton
Mathematica Programming Group           paulh at
Wolfram Research, Inc.
Disclaimer: Opinions expressed herein are those of the author alone.

  • Prev by Date: Re: Word wrap doesn't happen
  • Next by Date: Re: Re: Re: circumference of an ellipse
  • Previous by thread: Re: ReplaceAll in If Statement
  • Next by thread: Re: ReplaceAll in If Statement