[ENH] Another new idiom for conditional testing?
Andres Valloud
sqrmax at prodigy.net
Tue Oct 2 19:30:24 UTC 2001
Hi.
[Changed the first line into a block, threw in a pair of parenthesis]
> = aRenameVariableChange
> ^([self class = aRenameVariableChange class],
> [className = aRenameVariableChange changeClassName],
> [isMeta = aRenameVariableChange isMeta],
> [oldName = aRenameVariableChange oldName],
> [newName = aRenameVariableChange newName]) allTrue
Unary selector? No kidding! It just reads "I am equal to xyz if all
these things are true"! This is great!!!
> The resulting pattern is not bad, but the implementation creeps me out a
> bit... adding messages and subclasses to Boolean and BlockContext is a
> bit extreme for my taste...
Making it very simple, and just supporting what we want lets us see
that:
* We don't need single blocks to be polymorphic with booleans.
* We don't need BlockContextComposites to understand ifTrue: ifFalse:
etc, just allTrue, allFalse, etc.
So, let's just
1. Add #, to BlockContext.
2. Object subclass: BooleanCondition.
There's something extra, a particular approach that would deliver an
even smaller implementation. We can cascade the queries to the
condition, so there's no need to implement ifAllTrue:ifAllFalse:,
ifAnyTrue:ifAnyFalse: neither the more logically complete
ifAllTrue:ifAnyTrue:ifAllFalse:, plus all its combinations, negations
and permutations.
Here's the tiny tiny implementation, with tests. It just came out so
beautifully!
Andres.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: allBoolean.zip
Type: application/x-compressed
Size: 1361 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20011002/83f1dec3/allBoolean.bin
More information about the Squeak-dev
mailing list
|