[squeak-dev] Question about #caseOf:otherwise:

Thiede, Christoph Christoph.Thiede at student.hpi.uni-potsdam.de
Thu Aug 15 12:08:24 UTC 2019


Why can't we apply the "hybrid" solution from #ifNotNil: here? Afaik the argument is inlined if it's a block, otherwise not. Specifying something inefficient is not recommended, but possible.


Von: Levente Uzonyi
Gesendet: Donnerstag, 15. August, 13:32
Betreff: Re: [squeak-dev] Question about #caseOf:otherwise:
An: The general-purpose Squeak developers list


On Thu, 15 Aug 2019, Thiede, Christoph wrote: > > 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.']. > }. While you could expect that to compile, the Parser is strict about the format, because everything (blocks, associations, the array) will be inlined, so no objects will be created for them. Without inlining, such construct would not be viable performance-wise. Levente > > Best, > Christoph > > _________________________________________________________________________________________________________________________________________________________________________________________________________________________________ > Von: Squeak-dev 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/2fc04220/attachment.html>


More information about the Squeak-dev mailing list