Re: Nested Repeat loops

2014-06-24 Thread Peter Haworth
Submitted QCC report 12691  for this.

Pete
lcSQL Software 
Home of lcStackBrowser  and
SQLiteAdmin 


On Sat, Jun 21, 2014 at 3:00 PM, Alex Tweedly  wrote:

> On 21/06/2014 15:22, Richard Gaskin wrote:
>
>> At the RevLive conference in Vegas a few yeas back, Robert Cailliau's
>> opening keynote covered some of the most adventurous feature requests I've
>> ever heard anyone suggest for xTalks.
>>
>> Among them was the notion of named control structures, in part for
>> exactly the reason covered in this thread, the desire to exit a specific
>> loop when loops are nested.
>>
>> I can't recall the specifics of his proposed syntax, but I remember being
>> impressed by how natural it seemed.  Maybe it was along the lines of:
>>
>>   repeat with i = 1 to tSomething named "MySomethingLoop"
>>   repeat with j = 1 to tSomethingElse named "MyOtherLoop"
>> DoSomethingWith i,j
>> exit "MySomethingLoop"
>>   end repeat
>>   end repeat
>>
>> With named control structures we'd never need to worry about line numbers.
>>
>> I'm not sure if that was submitted as a feature request, but IMO it
>> should be.  And it would be cool to have just about everything else he
>> proposed go into the DB as well - all of it was valuable, very
>> forward-thinking, reflecting the best of many other languages, all
>> presented in a very xTalk way.
>>
> I believe it would be even better to (be able to) name both ends of the
> control structure, and thereby get some extra help from the compiler if
> there was any mismatch, as well as a better visual clue when reading the
> code. (Without this, when you see an "exit repeat 'name'" statement you
> need to look backwards to see the named control structure, and then
> forwards to find the matching end; far easier to have the name at the end
> as well).
>
>   repeat for each key K in myArray named "arrayloop"
>   repeat with i = 1 to 1000
>  if someFunc(K,i) then
>  doit K, i
>  next repeat "arrayloop"
>  end if
>  end repeat
>  if something() then exit repeat "arrayloop"
>   end repeat named "arrayloop
>
> IMO, either or both named clauses should be optional - no need to put in
> both unless you choose to do the extra work for the extra convenience of
> compiler checks, cf. explicitvariables.
>
> -- Alex.
>
>
> ___
> use-livecode mailing list
> use-livecode@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@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Nested Repeat loops

2014-06-21 Thread Alex Tweedly

On 21/06/2014 15:22, Richard Gaskin wrote:
At the RevLive conference in Vegas a few yeas back, Robert Cailliau's 
opening keynote covered some of the most adventurous feature requests 
I've ever heard anyone suggest for xTalks.


Among them was the notion of named control structures, in part for 
exactly the reason covered in this thread, the desire to exit a 
specific loop when loops are nested.


I can't recall the specifics of his proposed syntax, but I remember 
being impressed by how natural it seemed.  Maybe it was along the 
lines of:


  repeat with i = 1 to tSomething named "MySomethingLoop"
  repeat with j = 1 to tSomethingElse named "MyOtherLoop"
DoSomethingWith i,j
exit "MySomethingLoop"
  end repeat
  end repeat

With named control structures we'd never need to worry about line 
numbers.


I'm not sure if that was submitted as a feature request, but IMO it 
should be.  And it would be cool to have just about everything else he 
proposed go into the DB as well - all of it was valuable, very 
forward-thinking, reflecting the best of many other languages, all 
presented in a very xTalk way.
I believe it would be even better to (be able to) name both ends of the 
control structure, and thereby get some extra help from the compiler if 
there was any mismatch, as well as a better visual clue when reading the 
code. (Without this, when you see an "exit repeat 'name'" statement you 
need to look backwards to see the named control structure, and then 
forwards to find the matching end; far easier to have the name at the 
end as well).


  repeat for each key K in myArray named "arrayloop"
  repeat with i = 1 to 1000
 if someFunc(K,i) then
 doit K, i
 next repeat "arrayloop"
 end if
 end repeat
 if something() then exit repeat "arrayloop"
  end repeat named "arrayloop

IMO, either or both named clauses should be optional - no need to put in 
both unless you choose to do the extra work for the extra convenience of 
compiler checks, cf. explicitvariables.


-- Alex.

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Nested Repeat loops

2014-06-21 Thread Peter Haworth
Thanks for all the suggestions.  I like the idea of putting the whole nest
of repeats in a separate handler as far as the current capabilities of the
language, but I really like the idea in Richard's email to have the ability
tp name each loop then exit out of a named loop.  Is there a QCC report on
that already? If not, I'll put one in.

Pete
lcSQL Software 
Home of lcStackBrowser  and
SQLiteAdmin 



>
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Nested Repeat loops

2014-06-21 Thread Richard Gaskin

Peter M. Brigham wrote:

On Jun 21, 2014, at 2:33 AM, Richmond wrote:


put 1 into XX
repeat until XX>7
 do something
   put 1 into ZZ
   repeat until ZZ>7
 do something else
put 1 into YY
   repeat until YY>7
   ask "What colour are you socks?"
  if it contains "purple" then
  goto %%%
  end if
  add 1 to YY
end repeat
 add 1 to ZZ
 end repeat
  add 1 to XX
end repeat
%%%


I like this. The syntax could be
   go %n -- eg, %4

then the execution would jump to the statement
   %n -- eg, %4

(Which would allow really flexible GOTO equivalents that would be independent 
of script line numbering. I always struggled with the Fortran GOTO statements, 
since I was always having to renumber my lines when I revised my programs.)

Enhancement request, anyone?


At the RevLive conference in Vegas a few yeas back, Robert Cailliau's 
opening keynote covered some of the most adventurous feature requests 
I've ever heard anyone suggest for xTalks.


Among them was the notion of named control structures, in part for 
exactly the reason covered in this thread, the desire to exit a specific 
loop when loops are nested.


I can't recall the specifics of his proposed syntax, but I remember 
being impressed by how natural it seemed.  Maybe it was along the lines of:


  repeat with i = 1 to tSomething named "MySomethingLoop"
  repeat with j = 1 to tSomethingElse named "MyOtherLoop"
DoSomethingWith i,j
exit "MySomethingLoop"
  end repeat
  end repeat

With named control structures we'd never need to worry about line numbers.

I'm not sure if that was submitted as a feature request, but IMO it 
should be.  And it would be cool to have just about everything else he 
proposed go into the DB as well - all of it was valuable, very 
forward-thinking, reflecting the best of many other languages, all 
presented in a very xTalk way.


--
 Richard Gaskin
 Fourth World
 LiveCode training and consulting: http://www.fourthworld.com
 Webzine for LiveCode developers: http://www.LiveCodeJournal.com
 Follow me on Twitter:  http://twitter.com/FourthWorldSys

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Nested Repeat loops

2014-06-21 Thread Peter M. Brigham
On Jun 21, 2014, at 2:33 AM, Richmond wrote:

> put 1 into XX
> repeat until XX>7
>  do something
>put 1 into ZZ
>repeat until ZZ>7
>  do something else
> put 1 into YY
>repeat until YY>7
>ask "What colour are you socks?"
>   if it contains "purple" then
>   goto %%%
>   end if
>   add 1 to YY
> end repeat
>  add 1 to ZZ
>  end repeat
>   add 1 to XX
> end repeat
> %%%

I like this. The syntax could be
   go %n -- eg, %4

then the execution would jump to the statement
   %n -- eg, %4

(Which would allow really flexible GOTO equivalents that would be independent 
of script line numbering. I always struggled with the Fortran GOTO statements, 
since I was always having to renumber my lines when I revised my programs.)

Enhancement request, anyone?

-- Peter

Peter M. Brigham
pmb...@gmail.com
http://home.comcast.net/~pmbrig





___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Nested Repeat loops

2014-06-21 Thread John Craig
You could wrap the repeats in a try structure - stick the following 
script in a button...


on mouseUp
   try
  repeat with i = 1 to 10
 repeat with j = 1 to 10
repeat with k = 1 to 10
   put i && j && k
   wait for 2 millisecs with messages
   if the shiftKey is down then throw "exit"
end repeat
 end repeat
  end repeat
   end try
end mouseUp


On 21/06/2014 02:18, Peter Haworth wrote:

Wondering if anyone has an elegant way of exiting all the way out of a set
of nested repeat loops.



___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Nested Repeat loops

2014-06-20 Thread Richmond

On 21/06/14 04:34, Dr. Hawkins wrote:

On Fri, Jun 20, 2014 at 6:18 PM, Peter Haworth  wrote:


Wondering if anyone has an elegant way of exiting all the way out of a set
of nested repeat loops., e.g:


It's a badly needed language addition, and one of the things I want from
Fortran.

Then again, I actually used a GOTO in the software for my dissertation,
after realizing it was the rare case one was called for, and had spent
hours making parallel sets of code to avoid it.  (not to mention what I did
with a trailing preposition in that last sentence!)




This is where some sort of "get out quickly" phrase is needed.

Yesterday one of my 12 year old 'victims'  was getting her feet wet with 
her first SWITCH statement,

and got badly bogged down, and we found that

exit switch

seemed to work a bit better than

break

the 'funny' thing is that the Dictionary (err: "Hitch Hiker's Guide to 
the Galaxy") says they are synonymous; but, as we linguists say 'no 2 
words are ever completely synonymous'.


I suppose a GOTO statement would be really good; especially as, although 
Livecode scripts
supposedly don't have line numbers, there are those numbers down the 
left-hand side :/


The only bother about those numbers is that every time one pops a bit of 
code into one's script they will refer to different places.


This sort of thing might not be bad:


put 1 into XX
repeat until XX>7
  do something
put 1 into ZZ
repeat until ZZ>7
  do something else
 put 1 into YY
repeat until YY>7
ask "What colour are you socks?"
   if it contains "purple" then
   goto %%%
   end if
   add 1 to YY
 end repeat
  add 1 to ZZ
  end repeat
   add 1 to XX
end repeat
%%%

Richmond.


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Nested Repeat loops

2014-06-20 Thread jbv
In some cases I managed to replace "repeat for" with
"repeat while" and thus eliminating the flag and the
test on it since the condition is in the repeat loop itself.

jbv

> Wondering if anyone has an elegant way of exiting all the way out of a set
> of nested repeat loops., e.g:
>
> repeat for...
>repeat for...
>   repeat for
>  repeat for
> if . then  here>
>  end repeat
>  
>   end repeat
>   
>end repeat
>
> end repeat
>
> Right now, I set a flag to true when the exit condition is met then test
> it
> in the  stuff.  Works fine but feels a little kludgy.
>
> Pete
> lcSQL Software <http://www.lcsql.com>
> Home of lcStackBrowser <http://www.lcsql.com/lcstackbrowser.html> and
> SQLiteAdmin <http://www.lcsql.com/sqliteadmin.html>
> ___
> use-livecode mailing list
> use-livecode@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@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Nested Repeat loops

2014-06-20 Thread Geoff Canyon
It's hard to say without context, but one way to handle things like this is
to fold it all into a function/handler. Then if you want to exit you can
exit/return.


On Fri, Jun 20, 2014 at 8:55 PM, J. Landman Gay 
wrote:

> I've needed that too occasionally but I've always had to set a flag like
> you do. We need an "exit all repeats" command.
>
> On June 20, 2014 8:18:59 PM CDT, Peter Haworth  wrote:
> >Wondering if anyone has an elegant way of exiting all the way out of a
> >set
> >of nested repeat loops.
> --
> Jacqueline Landman Gay | jac...@hyperactivesw.com
> HyperActive Software   | http://www.hyperactivesw.com
>
> ___
> use-livecode mailing list
> use-livecode@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@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Nested Repeat loops

2014-06-20 Thread Warren Samples

On 06/20/2014 08:18 PM, Peter Haworth wrote:

Wondering if anyone has an elegant way of exiting all the way out of a set
of nested repeat loops., e.g:

repeat for...
repeat for...
   repeat for
  repeat for
 if . then 
  end repeat
  
   end repeat
   
end repeat

end repeat

Right now, I set a flag to true when the exit condition is met then test it
in the  stuff.  Works fine but feels a little kludgy.

Pete


Maybe I've completely failed to understand what it is you don't like 
about your current method, but...


Would it be practical and feel cleaner to wrap your nested repeats 
inside a command, say,'doLoop'. When your 'if' condition in the nth 
repeat is met, you 'exit doLoop'. You only have to reference and check a 
condition once this way and you cleanly exit the entire nested structure 
exactly when and where the condition is found.


A useless example that works:

Create a card with four fields and a button. Put this script in the button:


 on mouseUp
   doLoop
   answer "exited loop"
end mouseUp

on doLoop
   repeat 10 times
  add 1 to field 1
  repeat 10 times
 add 1 to field 2
 repeat 10 times
add 1 to field 3
repeat 10 times
   if field 3 is 3 then exit doLoop
   add 1 to field 4
end repeat
 end repeat
  end repeat
   end repeat
end doLoop

Warren

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Nested Repeat loops

2014-06-20 Thread Jerry Jensen
Its not always easy, or worth the trouble, but putting the whole nested 
structure in a separate handler lets you use the exit command.
.Jerry

On Jun 20, 2014, at 6:55 PM, J. Landman Gay  wrote:

> I've needed that too occasionally but I've always had to set a flag like you 
> do. We need an "exit all repeats" command. 
> 
> On June 20, 2014 8:18:59 PM CDT, Peter Haworth  wrote:
>> Wondering if anyone has an elegant way of exiting all the way out of a
>> set
>> of nested repeat loops.
> -- 
> Jacqueline Landman Gay | jac...@hyperactivesw.com
> HyperActive Software   | http://www.hyperactivesw.com
> 
> ___
> use-livecode mailing list
> use-livecode@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@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Nested Repeat loops

2014-06-20 Thread J. Landman Gay
I've needed that too occasionally but I've always had to set a flag like you 
do. We need an "exit all repeats" command. 

On June 20, 2014 8:18:59 PM CDT, Peter Haworth  wrote:
>Wondering if anyone has an elegant way of exiting all the way out of a
>set
>of nested repeat loops.
-- 
Jacqueline Landman Gay | jac...@hyperactivesw.com
HyperActive Software   | http://www.hyperactivesw.com

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Nested Repeat loops

2014-06-20 Thread Dr. Hawkins
On Fri, Jun 20, 2014 at 6:18 PM, Peter Haworth  wrote:

> Wondering if anyone has an elegant way of exiting all the way out of a set
> of nested repeat loops., e.g:
>

It's a badly needed language addition, and one of the things I want from
Fortran.

Then again, I actually used a GOTO in the software for my dissertation,
after realizing it was the rare case one was called for, and had spent
hours making parallel sets of code to avoid it.  (not to mention what I did
with a trailing preposition in that last sentence!)


-- 
Dr. Richard E. Hawkins, Esq.
(702) 508-8462
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Nested Repeat loops

2014-06-20 Thread Peter Haworth
Wondering if anyone has an elegant way of exiting all the way out of a set
of nested repeat loops., e.g:

repeat for...
   repeat for...
  repeat for
 repeat for
if . then 
 end repeat
 
  end repeat
  
   end repeat
   
end repeat

Right now, I set a flag to true when the exit condition is met then test it
in the  stuff.  Works fine but feels a little kludgy.

Pete
lcSQL Software <http://www.lcsql.com>
Home of lcStackBrowser <http://www.lcsql.com/lcstackbrowser.html> and
SQLiteAdmin <http://www.lcsql.com/sqliteadmin.html>
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode