[squeak-dev] Question about #caseOf:otherwise:
Levente Uzonyi
leves at caesar.elte.hu
Thu Aug 15 11:52:42 UTC 2019
On Thu, 15 Aug 2019, Stéphane Rollandin wrote:
> Le 15/08/2019 à 10:32, Marcel Taeumel a écrit :
>> 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]"? :-)
>>
>
> The semantics would then change, because multiple tests could return
> true, and then it would have to be clear if only one case is taken into
> account, and which one (for example, the first), or if all cases are
> considered and then all associated blocks are evaluated (sequencially?).
>
> So while nice, it seems to me that this proposal opens a can of worms...
No, it doesn't, because the semantics are clear: only the first matching
branch is considered.
| a b c d |
a := 1.
b := 2.
c := 1.
d := c caseOf: {
[ a ] -> [ 'a' ].
[ b ] -> [ 'b' ].
[ c ] -> [ 'c' ] }.
self assert: d = 'a'
Levente
>
> My 2 cents,
>
> Stef
>
>
More information about the Squeak-dev
mailing list
|