[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: how expressive are they?
On Fri, 22 Nov 2002, Anton van Straaten wrote:
> BTW, I detect a certain lack of separation of concerns in the above. From a
> design perspective, wouldn't it be better to separate the 'if' out from all
> of those messages, so as to be able to more flexibly combine 'if' with
> things that don't already have 'if' in them, and similarly in order to be
> able to use the predicates independently of the 'if' form? Seems like it
> would be the object-oriented thing to do...
The following are all equivalent (as well as a few other permutations):
x == nil ifFalse: [y] ifTrue: [z]
x isNil ifFalse: [y] ifTrue: [z]
x isNil not ifTrue: [y] ifFalse: [z]
x notNil ifTrue: [y] ifFalse: [z]
x ifNotNil: [y] ifNil: [z]
Of course the conflated versions are implemented in terms of the more
separated versions - but if you're using "x isNil ifTrue: .." all the
time, why not shorten it to "x ifNil: ..."?
I would argue that one of the strengths of having such constructs not be
macros is that it makes people more likely to define specialized versions.
I have no idea why the Smalltalk community implemented an #ifNil: method,
and the Scheme community do not generally use an (ifnil? ) macro, but I
suspect it's that there's a greater reluctance to add new macros to the
language than to add new functions/methods. I'm not arguing that there
*should* be such reluctance, by the way, just that it seems to exist.