For Each Anomaly

Jim Ault JimAultWins at yahoo.com
Wed Jun 20 10:20:13 EDT 2007


On 6/19/07 9:40 PM, "Björnke von Gierke" <bvg at mac.com> wrote:

> This is looking completely wrong at the issue. A variable should be
> changeable, it's in the definition of the name. If a variable is not
> changeable it should be renamed to "constant" or maybe
> "don'ttouchthisthingy".

 Variable means that it can be defined, but not necessarily at any time to
any value.

In any programming language, or scripting language, the term 'variable'
comes with the discipline of 'type casting', which means not all variables
are the same, or same type, or serve the same purpose.

The repeat for each technique probably gets its speed from casting the set
of conditions, then looping through them, not expecting them to change.

The same thing can be witnessed in the following simple loop

repeat with x = 1 to the number of lines in field "colorsList"
  delete line x of field " colorsList"
end repeat

Here (the number of lines in field " colorsList") is evaluated before any
deletions, and Rev does not stop to re-evaluate.  Of course, this loop will
generate an error as soon as there is no "line x" because of deletions.

A programmer at any level will need to know the limitations and use of
variables, and the 'for each loop' is one of them.
> Basically any confusion for a user should be an opportunity to increase
> the reliability of the user experience. Scrutinising  a user or putting
> him down for being confused is a sure way to have one user less.
> Therefore, Rev should make the labelVariable changeable whenever any
> user wants, i'm pretty sure that'd be not a  problem to do for them (as
> it worked in earlier versions). Allowing changes to the container
> variable is probably much harder, but I'm sure something could be done
> about that too.
Some uses of variable definitions work faster and better if they are cast,
then not changed, or allowed to be changed.  I prefer to have the speed
offered by 'repeat for each' than have it changed to a method that requires
constant rechecking of the value of a 'variable'.

If Rev does this, I would hope they clearly label it to be different
repeat more slowly for each line LNN in myVar
   ...
end repeat

> 
> I also would like to add, that I often change label variables in repeat
> for each loops, and have had never any errors thrown because of it (or
> unexpected results). I did however get unexpected results from changing
> the container variable.

In my experience:
repeat for each line LNN in colorsList
   ...
end repeat
-->changing the value of LNN is risky, just as changing the value of 'x' in
the loop further above.  In some languages, the change is ignored, in
others, it generates an error.  If LNN contains something I wish to change,
I do the following steps...

get LNN
replace comma with space in it


Basically, I like it the way it is, and it is part of the definition.

Jim Ault
Las Vegas





More information about the use-livecode mailing list