For Each Anomaly
Jim Ault
JimAultWins at yahoo.com
Wed Jun 20 13:47:13 EDT 2007
On 6/20/07 8:56 AM, "Björnke von Gierke" <bvg at mac.com> wrote:
>> 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
>
> This is the only valid argument you have put forth. Speed is important,
> but again, if it is not changeable, no one should be able to change at
> all, and therefore it should be a constant, and not a variable.
> I could live with your proposed nomenclature, and would put forth this
> for the existing loop:
>
> constant myConstant = myVar
> repeat for each line with constant LNN in myConstant
> ...
> end repeat
To be sure, Björnke, computer languages can be confusing. Try Applescript
and its highly-unintuitive world of variables!! What a headache.
So let's look at the example you have shown above.
In this case, LNN cannot be a constant, since its value needs to update
every iteration. The key concept is that by using the "repeat for each"
form, the programmer has chosen to use LNN as a variable
*that is updated by Rev*, not the programmer, and 'myConstant' is an initial
condition that Rev is to use that will not change.
It is a matter of knowing which tools do what job, and the limitations that
need to be considered. To be able to modify variables during the loop, you
should consider the following repeat form, which works just fine ------
put empty into ImDone
put 1 into cntr
put fld 2 into textBlock
repeat until ImDone is not empty
if there is not a line cntr of textBlock then exit repeat --done
if line cntr of textBlock contains "keep" then
put " " before line cntr of textBlock
add 1 to cntr
else
delete line cntr of textBlock
end if
end repeat
put textBlock into fld 2
Speed is not only important to Rev, it is critical. Without this, we would
need to go back to the days of building an externals library, like Rinaldi,
etc. or write our own... which would make the general public rather unhappy
and Rev far less user friendly.
As Stephen expressed earlier, compilers and code execution are very complex,
and certain rules have to be followed or things get risky. As usual, faster
code has tighter rules.
Maybe there should be some area of the docs that addresses this issue of
power user tools vs general public tools. I know I had to spend
considerable time learning the better code techniques in Rev over the last 3
years.
Jim Ault
Las Vegas
More information about the use-livecode
mailing list