MathGroup Archive 2004

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

Search the Archive

Re: Sequential evaluation of lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg53108] Re: [mg53076] Sequential evaluation of lists
  • From: yehuda ben-shimol <benshimo at bgu.ac.il>
  • Date: Thu, 23 Dec 2004 07:59:50 -0500 (EST)
  • References: <200412220953.EAA04525@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

The evaluation is not always left to right. There are some cases that it 
goes from right to left, and it SHOULD do so.
L2R evaluation
{Print[a], Print[b], Print[c]};
results with
a
b
c
R2L evaluation
Print[d] & /@ {Print[e]} & /@ {Print[f]}
and get
f
e
d
{{Null}}
For your specific case (and others as well) of x=0;{x++,x++,x++} you can 
use Trace to follow the evaluation order
x=0;Trace[{x++,x++,x++}]
and get
{{x++, {x, 0}, {x = 1, 1}, 0}, {x++, {x, 1}, {x = 2, 2}, 1}, { x++, {x, 
2}, {x = 3, 3}, 2}, {0, 1, 2}}
or
Trace[{a=1,b=2,c=3}]
and get
{{a = 1, 1}, {b = 2, 2}, {c = 3, 3}, {1, 2, 3}}
yehuda
Ray Koopman wrote:

>When I first started using Mathematica (v2), one of the features that
>I found rather surprising is its sequential evaluation of lists, as in
>
>In[1]:= x = 0; {x++,x++,x++}
>Out[1]= {0,1,2}
>
>I had expected a warning that such code should be avoided because
>it presumed sequential evaluation, which could not be guaranteed,
>and a recommendation to treat list elements as being evaluated in
>parallel -- if not simultaneously then in no particular order.
>However, so far I have found no exception to sequential evaluation
>and no mention of it in any documentation. Have I missed something?
>
>  
>


  • Prev by Date: Excel Link Problem
  • Next by Date: Re: How to do Continued fraction of polynomials
  • Previous by thread: Re: Re: Sequential evaluation of lists
  • Next by thread: Re: Re: Sequential evaluation of lists