Re: Variables in Iterator limits?

*To*: mathgroup at smc.vnet.net*Subject*: [mg109630] Re: Variables in Iterator limits?*From*: "christopher arthur" <aarthur at tx.rr.com>*Date*: Sun, 9 May 2010 07:49:13 -0400 (EDT)

----- Original Message ----- From: "AES" <siegman at stanford.edu> To: <mathgroup at smc.vnet.net> Sent: Saturday, May 08, 2010 6:05 AM Subject: [mg109630] [mg109608] Variables in Iterator limits? > If I execute the following lines, I get the graphic that I want: > > x; Remove["Global`*"]; > > lines := Graphics[ Table[ Line[{{k 10/kmax,-1}, > {k 10/kmax,1}}], {k,1,kmax}]] > > km = 30; Show[lines] > but kmax is undefined? probably you don't mean 'km' but 'kmax' in last line. Then it works fine. > If I execute the following lines, I get exactly the same graphic, all OK, > > x; Remove["Global`*"]; > > lines := Graphics[ Table[ Line[{{k 10/kmax,-1}, > {k 10/kmax,1}}], {k,1,kmax}]] > > testValues = {kmax->30}; Show[lines] /. testValues > > -- except that I also get a beep, and an error msg in the Messages > window: > > "Iterator {k,1,kmax} does not have appropriate bounds" > The problem is the order of operations. The replacement rule is applied after Show[] executes (or attempts). This means that 'kmax' does not yet have a value. Perhaps the best way to think about it is to consider that the replacement rule won't change a length of a list in general but can change its contents. Christopher Arthur > (but no little red square in the graphics output cell). > > Same thing happens in the /. case if I do the two tests in reverse order. > > Seems like another annoying little Mathematica "gotcha" to me . . . ? > >