MathGroup Archive 1996

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

Search the Archive

Re: Re-evaluation of Conditional expressions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg3485] Re: Re-evaluation of Conditional expressions
  • From: Harald Berndt <haraldb at nature.berkeley.edu>
  • Date: Sat, 16 Mar 1996 22:39:39 -0500
  • Organization: University of California Forest Prodcts Lab
  • Sender: owner-wri-mathgroup at wolfram.com

Patrice Quinton wrote:
> 
> 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]
> ...
> Is there a special reason for this? Any way to circumvent this problem?
> 


-- 

Patrice:

You have an answer for the "why" from David. To circumvent the 
problem, use SetDelayed[] rather than Set[], i.e.,

y := If[x,1,2]

This will evaluate the If[] at the time you call y, using whatever 
value x has at that time.

______________________________________________________________________
Harald Berndt,                                University of California
Research Specialist                         Forest Products Laboratory

Phone:	510-215-4224                                FAX:			510-215-4299

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


  • Prev by Date: Re: Re-evaluation of Conditional expressions
  • Next by Date: Re: Re-evaluation of Conditional expressions, wrong explanation
  • Previous by thread: Re: Re-evaluation of Conditional expressions
  • Next by thread: Re: Re-evaluation of Conditional expressions