[Grace-core] Assignment return values and null

James Noble kjx at ecs.vuw.ac.nz
Tue Jun 26 06:32:45 PDT 2012


> I'm not sure I would call this "nice" -- in my opinion it mainly
> demonstrates that there's a real need for proper break/continue
> statements in Grace. Passing around and applying 'break' blocks would
> most likely seem pretty arbitrary to beginners.

so this is a good point, really, and I know I've avoided it - 
or at least not really engaged with it directly
(although I do quite like the loop/return solution).
Python has break & continue; Ruby does too (break & next)
and also redo and retry and until and unless and ...

There are a least three questions here - one is: 
 - should people teach with break & continue?
 - will people want to teach with break & continue?
 - will people give up on Grace without b & c?
 - can b&c be implemented in Grace as a dialect?

the last question is in some sense the most important.
The blog post shows this can be done by passing in exit blocks;
that solution is quite "pure", but having to write "break.apply"
isn't as nice (Ok, as "Graceful") as just writing "break".

Note that I'm not concerned about the code required to define
loop/break/continue/whatever --- that code would be written
by experienced instructors i.e. us -- it should be _explicable_
but it doesn't have to be _obvious_ 

So, if we had exceptions, I think we can write loop, break & continue
that would work the way C & Java programmers expect.   

method break {BreakException.raise}
method continue {ContinueException.raise}

method loop (body : Block) { 
  catch { 
     while (true) do { 
         catch (body) 
             case { ContinueException -> }      
     }
  } 
     case { BreakException -> }  
} 

Now break & continue should work as expected, although
they have dynamic extent rather than static, and no doubt
would end up rather slow without special compiler support.
This really won't do the right thing with nested loops, 
especially across method boundaries.

But it's nice to know we could something if we needed to.
Whether this should be in a standard library, or an addon with 
extra control structures (import bcpl :-)  is another question! 

I wonder if we need to look at delimited continuations to do this properly?

James


More information about the Grace-core mailing list