[ANN] Null Pattern implementation

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[ANN] Null Pattern implementation

keith1y
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 

Reply | Threaded
Open this post in threaded view
|

Re: [ANN] Null Pattern implementation

karl-8
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