What would Squeak be like without non-local returns

Rob Withers reefedjib at yahoo.com
Tue Nov 6 23:48:20 UTC 2007


I'll just throw this out and see what turns up.   As you have probably heard, I am toying with adding eventual refs to Squeak.  Unfortunately, they don't play well with non-local returns.  Igor and I had been discussing what could be done with methods having non-local returns adn it is looking nasty.   So I thought to look at another piece of the puzzle and question its existence.  
 
How important is non-local return to Squeak?  What would Squeak look like without it?
 
So I thought of the first use of it, detecting an object in a collection.  Here is #detect:ifNone: with non-local return:
 
detect: aBlock ifNone: exceptionBlock 
    self do: [:each | (aBlock value: each) ifTrue: [^ each]].
    ^ exceptionBlock value
 
and here is a version without non-local return:
 
detectNoNonLocalReturn: aBlock ifNone: exceptionBlock 
    | foundElement index each |
    index := 1.
    [foundElement isNil and: [index <= self size]] whileTrue: [
        (aBlock value: (each := self at: index)) ifTrue: [foundElement := each].
        index := index + 1].
    ^ foundElement isNil
        ifTrue: [exceptionBlock value]
        ifFalse: [foundElement].


Hopefully someone can do better.  As it stands it is much worse and I just don't know how to program in Squeak without non-local returns.  It feels like there is a missing helper method in there or something.  I don't know.  At the point of detection we know we want to return that thing and the rest of this mathod just transfers it down to the end of the method.  Noise.

Tell me what you think!

Cheers,
Rob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20071106/a9e06947/attachment.htm


More information about the Squeak-dev mailing list