Re: FOR i ...

new topic     » goto parent     » topic index » view thread      » older message » newer message

Pete Lomax wrote:
> 
> 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):
> }}}
<eucode>
>   for integer=1 to 10 do end for
>   for atom=1 to 10 do end for
> </eucode>
{{{

> 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, 

Actually, the parser expects a variable name and an equal sign, so it has to be
modified for your syntax to work. It is a workable solution.

> thus I propose:
> }}}
<eucode>
>    integer i
>    for integer i=1 to 10 do -- re-uses existing i
>    end for
>    ?i  -- valid, prints 11
> </eucode>
{{{

> 
> 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.
> 

NO
type hour(integer n)
return n>=0 and n<=23
end type
hour n
for hour n=0 to 23 do big_ben_chime() end for

This should be legal, shouldn't it?
This is why I'd prefer either the "with" version Derek proposed, or a new
keyword like iterate, rather.

CChris

> 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.

If we agree that regular loop indexes don't need to show up in ex.err unless the
loop they relate to is active, then it can be solved (by setting them to NOVALUE
on exiting the loop). This would permit to show them as undefined while tracing,
since a for loop index is always initialised.

CChris

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu