[ANSI-Smalltalk] Re: A list of interesting methods, ifNotNil:

Peter van Rooijen peter at vanrooijen.com
Mon Sep 8 19:39:50 BST 2008


On Mon, 08 Sep 2008 06:09:48 +0200, Richard A. O'Keefe <ok at cs.otago.ac.nz>  
wrote:

>
> On 5 Sep 2008, at 5:33 pm, Paolo Bonzini wrote:
>> I'll just point out that #ifNotEmptyDo:, for me is a shortcut for
>>
>>   x isEmpty ifTrue: [ x do: monadicBlock ]
>>
>> which is a good reason for supporting bi-arity instead of overloading
>> the meaning of "do".
>
> I am now confused.
> The actual code in Squeak is
>
> 	ifNotEmptyDo: aBlock
> 	    ^self isEmpty ifTrue: [aBlock value: self]

That is still bizarre, if you ask me...

> It certainly doesn't involve any sending of the message #do:.

No. I think Paolo meant that he would read it like that.
It would feel to him as if a #do: iteration was implied.
(I suspect this is what Paolo meant).

I personally don't have that feeling with the -Do: suffix,
but rather that the receiver of the 'conditional' message
will be passed in, saving storing it in a temp.

Perhaps I picked this up from living in VA for many years,
I don't know. But I've come to find it rather 'intuitive'.
I don't think it would bother me at all to have this
pattern for distinguishing between passing in the receiver
or not doing so, in a library (standard).

Consistent application of such a pattern would of course
mean that #ifNotNil: would work with a niladic block
and #ifNotNilDo: would work with a monadic block.

Whether the messages would support any other arities could
be left unspecified by the standard, couldn't it?

Regards, Peter

> x isEmpty ifTrue: [x do: monadicBlock]
>
> would, if x is a collection, never do anything at all with monadicBlock.
> I take it that this should have been
>
> x isEmpty ifFalse: [x do: monadicBlock]
>
> and there is a name for that too:  #do:.
>
> VisualWorks also has an if*Do: method or two.
> GeneralBindingReference>>ifDefinedDo:
> has nothing to do with #do:.
> WindowManager>>activeControllerProcessIfBlockedDo:
> also has nothing to do with #do:.
>
>
>
> 	
>
> _______________________________________________
> ANSI-Smalltalk mailing list
> ANSI-Smalltalk at lists.openskills.org
> http://lists.openskills.org/cgi-bin/mailman/listinfo/ansi-smalltalk
>



-- 
Peter van Rooijen
Esstede 19
1112 EP Diemen
m: 06-2854 2048



More information about the ANSI-Smalltalk mailing list