[squeak-dev] Question about #caseOf:otherwise:
Thiede, Christoph
Christoph.Thiede at student.hpi.uni-potsdam.de
Thu Aug 15 09:20:04 UTC 2019
Sounds very interesting :)
In the past I have been writing the following instead:
true caseOf: {
[aNumber isEven] -> ['That is an even number.'].
[aNumber isOdd] -> ['That is an odd number.'].
}.
but your code is much more beautiful :)
I think both variants have a contrary semantic, but on the other hand it just reads intuitive:
aNumber caseOf: {
[42] -> ['That is correct.'].
[:n | n even] -> ['That is an even number.'].
[:n | n odd] -> ['That is an odd number.'].
}.
This would also require some changes to the Parser. If your examples compiles, I would also expect the following to run:
aNumber caseOf: {
#even -> ['That is an even number.'].
#odd -> ['That is an odd number.'].
}.
Best,
Christoph
________________________________
Von: Squeak-dev <squeak-dev-bounces at lists.squeakfoundation.org> im Auftrag von Taeumel, Marcel
Gesendet: Donnerstag, 15. August 2019 10:32:07
An: gettimothy via Squeak-dev
Betreff: [squeak-dev] Question about #caseOf:otherwise:
Hi all!
Why isn't the following example possible?
aNumber caseOf: {
[:n | n even] -> ['That is an even number.'].
[:n | n odd] -> ['That is an odd number.'].
}.
That is, why is the check "assoc key value = self" not configurable as "(x := assoc key cull: self) == true or: [x = self]"? :-)
... maybe it is a good thing that case-of statements in Smalltalk are not that powerful?
Best,
Marcel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20190815/6621d25d/attachment.html>
More information about the Squeak-dev
mailing list
|