hlovatt schrieb:
> Tennent's book is quite old and talks about Pascal, I don't recall any
> specific discussion of exceptions and exceptions were not part of
> standard Pascal. So my guess is that any form of non-local jumps would
> not be covered by Tennent directly. The princiople says that the
> meaning of the code should not change if enclosed in a block, e.g.
> while loop, but it means any type of block and therefore also a try
> catch block.

I found out it is from around 1977, another reason why it is so hard to 
find... citeseer doesn't have papers that old ;) But I also think that 
an exception would be counted as exit point. On the other hand 
simulating an exception by control variables is not very nice.

> So my reading is that any form of non-block structured jump is
> excluded by the principle, i.e. no return, break, continue, or throw
> statements. All these have to be simulated with a status variable.
> Interestingly if an inner class was used instead of a block then a
> control variable could be used and exceptions avoided all together:
> 
> enum Status { CONTINUE, BREAK; }
> 
> class Loop implements Method1< Void, Object > {
>   Status status = CONTINUE;
>   void breakLoop() { status = BREAK; }
> }
> 
> class List {
>   private Object[] data;
>   ...
>   void each( Loop l ) {
>     for ( int i = 0; i < data.length && l.status == CONTINUE; i++ )
> { l.call( data[ i ] ); }
>   }
> }
> 
> // My favourite syntax follows!
> list.each method( e ) { if ( someCondition ) { breakLoop() } };

but you are not showing that the call to breakLoop() has to be at a 
position where no further commands follow. so if you have

while (true) {
    println "1"
    if (b) break;
    println "2"
}

you would have to split it in a b==true and b!=true part:

while (doLoop) {
    if (b) {
      println "1"
      doLoop=false
    } else {
      println "1"
      println "2"
    }
}

which might have less exit points, but is also less readable in my eyes. 
All in all it seems I will be no fan of Tennent's idea. In my last post 
I used something compareable to your breakLoop() command, but I had in 
mind that it throws an exception, that is cached before the block is 
left and then a iterator method from outside could handle that.... in 
your case, instead of doing a simple l.call you would have to put a 
try-catch around to be able to skip parts of the contents of your Loop 
subclass.


  bye blackdrag

-- 
Jochen "blackdrag" Theodorou
Groovy Tech Lead (http://groovy.codehaus.org)
http://blackdragsview.blogspot.com/
http://www.g2one.com/

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "JVM 
Languages" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/jvm-languages?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to