Thanks eveybody,

^ something aMsg ifNotNil: [ aNotherResult ]
is much more prety indded :)

Abdelghani



De : Peter Uhn��k <i.uhnak@gmail.com>
�� : abdelghani ALIDRA <alidrandco@yahoo.fr>; Any question about pharo is welcome <pharo-users@lists.pharo.org>
Envoy�� le : Mardi 30 juin 2015 13h26
Objet : Re: [Pharo-users] an elegant way to return a result

No need to have both if you are returning the receiver.

^ something aMsg ifNotNil: [ aNotherResult ]

For example try printing these two lines
1 ifNotNil: [ true ]. "true"
nil ifNotNil: [ true ]. "nil"

If you are interested in the implementation details I highly recommend to look at the implementation.
ProtoObject>>ifNotNil: aBlock
and
UndefinedObject>>ifNotNil: aBlock.

Peter



On Tue, Jun 30, 2015 at 1:21 PM, abdelghani ALIDRA <alidrandco@yahoo.fr> wrote:
Hi guys,

what is the best way to express the following :
return (something aMsg) if it is not nil, return somethingElse elsewhere

I could stil write:

something aMsg
    ifNil:[^ something aMsg]
    ifNotNil:[^aNotherResult]

but it sounds a little bit weird

Regards.

Abdelghani