Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1999
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1999

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

Search the Archive

Re: ReplaceAll in If Statement

  • To: mathgroup at smc.vnet.net
  • Subject: [mg19463] Re: [mg19448] ReplaceAll in If Statement
  • From: "Wolf, Hartmut" <hwolf at debis.com>
  • Date: Sat, 28 Aug 1999 15:52:58 -0400
  • Organization: debis Systemhaus
  • References: <199908250525.BAA24791@smc.vnet.net.>
  • Sender: owner-wri-mathgroup at wolfram.com

Tom Compton schrieb:
> 
> 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}}
> 
Tom, you'r right the test doesn't evaluate to True, instead it evaluates
to {True}! 

If you define

In[5]:= test2[opts___] := Module[{}, If[a /. opts, z = 1, z = 2, z = 3];
    {a, z} /. opts]
In[6]:= test2[opList]
Out[6]= {True, 1}

you'll get what you want (which is the same if you do):

In[7]:= test[a -> True]
Out[7]= {True, 1}

But perhaps you like this 

In[13]:= Thread[Unevaluated[test[{a -> True, a -> False, a -> "?"}]]]
Out[13]= {{True, 1}, {False, 2}, {"?", 3}}

yours, hw



  • Prev by Date: Re: Simultaneous nonlinear Regression of two data sets
  • Next by Date: Re: Please help me! (Warnings and Messages...)
  • Previous by thread: Re: ReplaceAll in If Statement
  • Next by thread: Re: ReplaceAll in If Statement