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

Levente Uzonyi leves at caesar.elte.hu
Thu Aug 15 13:02:01 UTC 2019


On Thu, 15 Aug 2019, Thiede, Christoph wrote:

> 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.

It is applied. If the argument is an array, it'll be inlined, if it's a 
variable, it can't and won't be inlined.

Levente

> 
> 
> 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 > >
> 
> 
>


More information about the Squeak-dev mailing list