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

Andres Valloud andres.valloud at gmail.com
Thu Sep 25 10:35:42 BST 2008


I am just wondering now... let's say one writes something like this:

something ifNilDo: [:nilObject | nilObject doWhatever]

This does not seem to make a lot of sense because if ifNilDo:
evaluates the block, then the argument is known to be nil.  So let's
look at this one

something ifNotNilDo: [:someObject | someObject doWhatever]

Why is this actually useful?  I am not saying it's not, but I am
having trouble seeing the reason.  Since the receiver is known at this
time, then I'd be tempted to do something like this:

something ifNotNilDo: [something doWhatever]

and skip the block argument.  One could say "ah but then this requires
a temp var".  However, expressions such as

something blah ifNotNilDo: [:something | something doWhatever]

are only possible to write without parentheses when "something blah"
does not have keyword messages in it... which is something that I try
to avoid as much as possible...

Is this the only gain?

Andres.


On Mon, Sep 8, 2008 at 11:50 AM, Paolo Bonzini <bonzini at gnu.org> wrote:
>
>>>     ifNotEmptyDo: aBlock
>>>         ^self isEmpty ifTrue: [aBlock value: self]
>>
>> That is still bizarre, if you ask me...
>
> Uhm, indeed.  Paste-o or bug!?
>
>>> 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).
>
> Yes, thanks for helping decyphering my messages. :-)
>
> Paolo
>
> _______________________________________________
> ANSI-Smalltalk mailing list
> ANSI-Smalltalk at lists.openskills.org
> http://lists.openskills.org/cgi-bin/mailman/listinfo/ansi-smalltalk
>



More information about the ANSI-Smalltalk mailing list