It would be an overkill to do it for this particular case, but Smalltalk makes it possible to implement a case-like construction: [ expression ] when: [ :value | condition1 ] do: [-0do :value | ... ]; when: [ :value | condition2 ] do: [ :value | ... ]; otherwiseDo: [ :value | ... ]; evaluate I am sure, something like this has been implemented already somewhere (maybe in Squeak?). Still not sure it is practical as compared to simple if-s, and for sure not widely used :) ...On the other hand, sometimes the case-like construction can be considered a more intension-revealing style. пÑ, 27 дек. 2019 г., 22:18 Roelof Wobben via Pharo-users < pharo-users@lists.pharo.org>:
Hello,
Im trying to solve a challenge from exercism where I have to calculate the points somehow gets on a very simple darts board.
I solved it like this :
scoreX: anInteger y: anInteger2 | distance | distance := (anInteger squared + anInteger2 squared) sqrt. distance > 10 ifTrue: [ ^ 0 ]. distance > 5 ifTrue: [ ^ 1 ]. distance > 1 ifTrue: [ ^ 5 ]. ^ 10
but now I use three if then and I think it's ugly code.
Is there a way I can make it more the smalltalk way ?
Regards,
Roelof