How to use an array to solve the following...

Bob Sneidar bobs at twft.com
Tue Feb 21 13:03:54 EST 2012


Even with repeat for each line, the chunk has to be parsed in memory for returns before proceeding. An array is by nature already parsed. As has been discussed before, the repeat for each command is so fast because it parses the memory used by the chunk, creating a list of pointers (forgive me if that is the wrong word) to the delimiters. It only has to do this once, as opposed to each time through the loop which is what makes it so fast. An array is already parsed, although the engine may reparse it for the purposes of the command, I do not know. 

Repeat for each line x in the keys of array y would seem at a glance to have to reevaluate the keys of <array> each time through the loop, wouldn't it? You must mean you get the keys first in a variable and then use that. 

Bob


On Feb 20, 2012, at 6:54 PM, Pete wrote:

> Interesting, and it kinda makes sense.  For elements, there's no
> positioning required like with lines/words/item, just a case of cycling
> through the keys - which is what "repeat for each line <x> in the keys of
> <array> does I suppose.
> Pete
> 
> On Mon, Feb 20, 2012 at 6:20 PM, Geoff Canyon Rev <gcanyon+rev at gmail.com>wrote:
> 
>> Certainly correct, but there is not the tremendous performance advantage to
>> using "for each element in..." For items, lines, and words, using
>> "item/line/word of myContainer" gets worse the larger the container is. For
>> character and with arrays, it doesn't. In my quick testing here, there's
>> just about no performance advantage to doing repeat for each element.
>> There's about a 4x benefit for using "repeat for each char" over "repeat
>> with i = 1 to length(myString)" But note that it seems to be 4x regardless
>> of the string length. That isn't the case with items, lines, and words --
>> there, the longer your container, the more you'll suffer.
>> 
>> 
>> On Mon, Feb 20, 2012 at 3:02 PM, Bob Sneidar <bobs at twft.com> wrote:
>> 
>>> Also each element in <array>
>>> 
>>> Bob
>>> 
>>> 
>>> On Feb 20, 2012, at 10:34 AM, gcanyon+rev wrote:
>>> 
>>>> any time you find yourself writing:
>>>> 
>>>> repeat with i = 1 to the number of lines|words|items of someContainer
>>>> 
>>>> stop. Rewrite it as:
>>>> 
>>>> repeat for each line|word|item in someContainer
>>> 
>>> 
>>> _______________________________________________
>>> use-livecode mailing list
>>> use-livecode at lists.runrev.com
>>> Please visit this url to subscribe, unsubscribe and manage your
>>> subscription preferences:
>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>> 
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>> 
>> 
> 
> 
> -- 
> Pete
> Molly's Revenge <http://www.mollysrevenge.com>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list