Re: trace(1) bug

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

c.k.lester wrote:
> 
> 
> Do you mean if I reuse a variable in a for loop, it
> should be considered local to that for loop?
> 
> i = 324
> for i=1 to 10 do
>   ?i -- 1,2,3,4,5,6,7,8,9,10
> end for
> ?i -- 324
> 
> What if I want to use the i that equals 324 in the loop?
> 
> Anyway, my point is I would never want to use a pre-defined variable
> in a for loop, and neither would anybody else. :D
> 
> > I will accept what you say - that if people code wrong they will get wrong
> > results. But why force procedures that complicate matters - and require more
> > variables - just so that people can use already defined variables a second
> > time without fouling up the earlier usage. Surely it isn't too much to
> > expect
> > programmers to use different variables for different values?
> 
> What are the benefits of allowing the use of a pre-declared var in a loop?
> 
> Of course I want Euphoria to improve. :)

It's good to bat these ideas about to get an improvment in the language...

It is clearly not a good idea to have a single variable name taking two
different values simultaneously in any part of the code.  So when Euphoria
insists that if I declare i as a loop iterator then it MAY NOT be already
in scope or you get this conflict. But that is true ONLY if the interpreter
is not allowed to use the pre-existing variable.

Actually I can see some merit in what is done now; if a loop iterator can 
use existing variables then it must be able to use program-global variables
too, which might cause errors.  So OK, we keep what we have but if the loop 
iterator is to use a pre-existing variable then have something with a buzz-word
like:
   for using i=1 to 10 do
which would be clear to users that the i is to be a variable already in scope.

I still think that if a variable i is used as a for-loop iterator, and goes out
of scope outside the loop, that to disallow any other i to become in scope is
a bit of a limitation - although it does probably reduce programming errors.

I think I have stirred the muddy waters enough on this one; I will now do
what most of you hope and shut up.  ;D

AndyD

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

Search



Quick Links

User menu

Not signed in.

Misc Menu