common code patterns

Mark Waddingham mark at livecode.com
Fri Aug 11 05:24:58 EDT 2017


On 2017-08-10 19:38, Ralph DiMola via use-livecode wrote:
> To make this even more flexible:
> 
> repeat for each line tLine in tLines with [counter] tIndex [start] 
> [{1}|x]
> [step] [{1}|y]
> 
> end repeat

Not quite on topic for the thread, but this interested in me in terms of 
- what are the use cases?

The common code pattern we see as justification for 'repeat for each 
line tLine and index tIndex in tLines' is that it allows you to use the 
efficiency of iteration over a primary container, whilst still retaining 
the index of the chunk being iterated over. i.e.

   put 0 into tIndex
   repeat for each line tLine in tContainer
     add 1 to tIndex
     if tLine is not line tIndex of tContainer then
       answer "Oh dear - something is *really* wrong"
     end if
   end repeat

So an extension to the syntax with 'index' means you get both pieces of 
information and a good amount of duality which justifies its existence.

In what kinds of situation do you find yourself wanting an offset index, 
relative to the index of the iterated chunk?

Warmest Regards,

Mark.

-- 
Mark Waddingham ~ mark at livecode.com ~ http://www.livecode.com/
LiveCode: Everyone can create apps




More information about the Use-livecode mailing list