I started creating a portability application and noticed that I get a compiler
error with the following method where it complains about emptyBlock:
ifNotEmptyDo: notEmptyBlock ifEmpty: emptyBlock
"Evaluate emptyBlock if I'm empty, notEmptyBlock otherwise
Evaluate the notEmptyBlock with the receiver as its argument"
^ self isEmpty ifFalse: [notEmptyBlock value: self] ifTrue: emptyBlock
however its sister method is fine?
ifEmpty: emptyBlock ifNotEmptyDo: notEmptyBlock
"Evaluate emptyBlock if I'm empty, notEmptyBlock otherwise"
"Evaluate the notEmptyBlock with the receiver as its argument"
^ self isEmpty ifTrue: emptyBlock ifFalse: [notEmptyBlock value: self]
Obviously I can work around it but it seems odd.
Tim
self isEmpty ifFalse: [notEmptyBlock value: self] ifTrue: [ emptyBlock
value ]
Dmitry Zamotkin
> #ifTrue:ifFalse: and #ifFalse:ifTrue: methods wait for block with
> brackets for optimization.
Yes you normally get the warning in the transcript but it usually works.
However in the case of ifFalse:ifTrue: it actually gives an error and refuses
to compile. This seems wrong especially when ifTrue:ifFalse: doesn't?
I have applied the change that you suggest - but it does seem like an inconsistency.
Tim
ifEmpty: emptyBlock ifNotEmptyDo: notEmptyBlock
^self isEmpty ifTrue: [emptyBlock value] ifFalse: [self do:
notEmptyBlock]
ifNotEmptyDo: notEmptyBlock ifEmpty: emptyBlock
^self ifEmpty: emptyBlock ifNotEmptyDo: notEmptyBlock