Bug 20255 - Simple Loop Labeling

Mark Waddingham mark at livecode.com
Fri Aug 11 05:51:12 EDT 2017


On 2017-08-10 21:33, Dr. Hawkins via use-livecode wrote:
> In fact, what I would *like* is modern Fortran style labelling or 
> something
> like that, and the ability to the those labels to controls like next 
> and
> exit.  This, however, would accomplish so much with so little.

Thinking out loud here and taking into account suggestions people have 
made in the past...

Naming loops in a syntactic way certainly sounds like a useful thing to 
do:

repeat for each line tLine in tContainer named LineLoop
   repeat for each item tItem in tLine named ItemLoop
     if some complicated condition then
       exit repeat ItemLoop
     else if some other complicated condition then
       exit repeat LineLoop
     end if

     -- do other stuff
     if some even more complicated condition then
       next repeat LineLoop
     end if
   end repeat ItemLoop
end repeat LineLoop

Certainly 'exit repeat ...' would not be harmful, 'next repeat ...' I'd 
have to analyze more deeply.

The main problem with GOTO (apart from the ability to create very hard 
to understand code) is that it allows creation of what is called 
'unstructured control-flow'. Basically that means that you have to work 
*exceptionally* hard to untangle it in a compile to perform any sort of 
reasonable optimization.

At present LiveCode only allows you to produce 'structured control 
flow'. Adding 'next repeat ...', doesn't change that... However, 'next 
repeat ...' is not so clear (I think it is probably fine, but need to 
check some algorithmics).

The only other issue with the above (beyond implementing it) is the 
syntax... It would reserve 'named' as a non-operator in this context. If 
we did ever have reason to have 'X named Y' then in repeats you'd have 
to do:

   repeat for each line tLine in (tContainer named ...) named ...

Although - without knowing what 'named' might do as an operator, or 
being able to think of anything it could do - that is probably a safe 
addition from that point of view.

(Of course we could use 'labelled' instead of 'named' in the repeat 
context - 'labelled' seems for some reason less likely to be leveragable 
as a binary operator!)

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