MathGroup Archive 1999

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

Search the Archive

Re: ReplaceAll in If Statement

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

In article <7q20sl$q9i at smc.vnet.net>, "Tom Compton" <comptont at concentric.net> 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?
>
>In[1]:=
>opList={a->True};
>
>In[2]:=
>test[opts___]:=Module[{},
>If[a /. {opts}, z=1, z=2, z=3];
>{a, z} /. {opts}]
>
>In[3]:=
>test[opList]
>Out[3]=
>{{True,3}}

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.com
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