[ANN] Null Pattern implementation

Karl karl.ramberg at chello.se
Tue Oct 17 13:40:22 UTC 2006


Keith Hodges wrote:
> I have resurrected Nevin Pratts Null Pattern implementation.
>
> http://www.squeaksource.com/Null
>
> See examples below.
>
> I also managed to get ifTrue:ifFalse: to work with the null pattern in 
> squeak.
>
> best regards
>
> Keith
>
> ----------
>
> Code like this:
>
>  | tmp |
>   tmp := person office.
>   tmp notNil ifTrue: [tmp := tmp phone].
>   tmp notNil ifTrue: [tmp := tmp lastNumberDialed].
>   tmp notNil ifTrue: [lastNumber := tmp asString].
>   widget setStringValue: lastNumber.
>
> becomes code like this:
>
> lastNumber := person office phone lastNumberDialed asString.
> widget setStringValue: lastNumber.
>
> Code like this:
>
> objectWantingControl
>
>
>   | ctrl |
>   ctrl := self getController.
>   ctrl isNil ifTrue: [^nil].
>   " Trap errors occurring while searching for
>   the object wanting control. "
>   ^Object errorSignal
>   handle: [:ex |
>   Controller badControllerSignal
>   raiseErrorString:
>   'Bad controller in objectWantingControl']
>   do: [ctrl isControlWanted ifTrue: [self] ifFalse: [nil]]
>
> becomes Code like this:
>
> objectWantingControl
>   self getController isControlWanted ifTrue: [^self].
>   ^nil
> Send instant messages to your online friends 
> http://uk.messenger.yahoo.com
>
Looks very nice.
Karl



More information about the Squeak-dev mailing list