Great, thank you! I will address the requested changes in the tests oon.


Best,

Christoph


Von: Squeak-dev <squeak-dev-bounces@lists.squeakfoundation.org> im Auftrag von Taeumel, Marcel
Gesendet: Donnerstag, 18. November 2021 10:51:45
An: squeak-dev
Betreff: Re: [squeak-dev] Merge Request: #caseOf:otherwise: with arguments
 
Merged.

Am 21.02.2020 17:33:03 schrieb Thiede, Christoph <christoph.thiede@student.hpi.uni-potsdam.de>:

This changeset makes it possible to accept an argument in the otherwise block of a #caseOf:otherwise: call.


Diff of the #caseOf:otherwise: implementation:

caseOf: aBlockAssociationCollection otherwise: aBlock

"The elements of aBlockAssociationCollection are associations between blocks.  Answer the evaluated value of the first association in aBlockAssociationCollection whose evaluated key equals the receiver.  If no match is found, answer the result of evaluating aBlock."


aBlockAssociationCollection associationsDo:

[:assoc | (assoc key value = self) ifTrue: [^assoc value value]].

- ^ aBlock value

+ ^ aBlock cull: self


"| z | z := {[#a]->[1+1]. ['b' asSymbol]->[2+2]. [#c]->[3+3]}. #b caseOf: z otherwise: [0]"

"| z | z := {[#a]->[1+1]. ['d' asSymbol]->[2+2]. [#c]->[3+3]}. #b caseOf: z otherwise: [0]"

"The following are compiled in-line:"

"#b caseOf: {[#a]->[1+1]. ['b' asSymbol]->[2+2]. [#c]->[3+3]} otherwise: [0]"

"#b caseOf: {[#a]->[1+1]. ['d' asSymbol]->[2+2]. [#c]->[3+3]} otherwise: [0]"

"#b caseOf: {[#a]->[1+1]. ['d' asSymbol]->[2+2]. [#c]->[3+3]} otherwise: [:x | x halt]"


Furthermore, the changeset includes a necessary modification of MessageNode >> #transformCase: so that the otherwise argument can be compiled in-line.

Last but not least, I wrote some tests for #caseOf:[otherwise:].


Please review!

(In a later change, it would be possible to allow arguments for the association key blocks as well. But I love short feedback loops, so let's assess this one first :-))


Best,

Christoph