Re: FOR i ...
- Posted by Pete Lomax <petelomax at blueyonder.??.uk> Nov 15, 2007
- 545 views
Derek Parnell wrote: > > the point of difference is whether or not the coder wants > the iterator variable to be declared in the FOR statement or prior Agreed, mostly [see PS]. > for <res-word> i = A to B by C do Fine by me. Experimenting, I found that (on both 2.4 & 3.1):
for integer=1 to 10 do end for for atom=1 to 10 do end for
compiles cleanly (but obviously does nothing). However any attempt to reference the [daftly named] control var, such as ?integer, triggers an error. Hence, I believe, the above proves A) that integer/atom could be used as the <res-word> with no changes to lexer/tokeniser, obviously changes are needed in the scanner no matter what <res-word> is, and B) such would not introduce any backward incompatibility, thus I propose:
integer i for integer i=1 to 10 do -- re-uses existing i end for ?i -- valid, prints 11
It should also be stated that, both for performance reasons and since it is illegal to modify a for loop control var, any attempts at user defined type checking on a for loop var simply won't happen. I'd further impose a compile time error on any attempt to use a udt. Regards, Pete PS Of course this does not actually solve the original problem of multiple and confusing i in trace/ex.err, <ahem> as my first suggestion did </ahem>, but at least provides a work-around, and an oft-requested missing feature.