MathGroup Archive 1996

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

Search the Archive

Re-evaluation of Conditional expressions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg3460] Re-evaluation of Conditional expressions
  • From: quinton at irisa.fr (Patrice Quinton)
  • Date: Sat, 9 Mar 1996 00:59:03 -0500
  • Organization: IRISA, Campus de Beaulieu, 35042 Rennes Cedex, FRANCE
  • Sender: owner-wri-mathgroup at wolfram.com

While teaching Mathematica, I found the following quite strange
behaviour of Conditional expressions in Mathematica. Define symbol y as follows:

y = If[x,1,2]

(* Then set x to True and revaluate y *)
x=True;y

(* as expected, the answer is 1 *)
(* Now, set x to z, a fresh symbol, and evaluate y *)
Clear[x,z];x=z;y

(* The result is If[x,1,2] *)

(* Finally, set z to True, and evaluate y *)
z=True;y

The result is still If[x,1,2], although a re-evaluation of x gives True, as
expected. 

The only way to get a re-evaluation of y is to use the function Update:

Update[];y 

which gives the result 1. In summary, it seems that If is re-evaluated only if
the expression that assigned to x has changed, and not when the value of x has
changed. 

Is there a special reason for this? Any way to circumvent this problem?

Thanks. 

Patrice Quinton 

Irisa, Campus de Beaulieu,
University of Rennes 1, France
Phone: 99 84 71 85, Fax: 99 84 71 71


==== [MESSAGE SEPARATOR] ====


  • Prev by Date: Re: Q: Getting interspike intervals in neuronal firing patterns
  • Next by Date: Re: "Do" help
  • Previous by thread: Kernel crashing with error 11 ??
  • Next by thread: Re: Re-evaluation of Conditional expressions