Does Smalltalk(especially Squeak/Pharo) have some form of variadic functions?
I was just reading about the power of designing your own control statments in smalltalk and while I’m a big fan of ifTrue: ifFalse: I was having a hard time coming up with a good way to implement arbitrary if,if else, if else,…,else statements thinking how useful Variadic functions those would be for implementing case statements. Something like
false class
ifTrue: aBlock (... elseIf: aBoolean then: aSecondBlock ...) else: aLastBlock
vArgList pairsDo: [:x :y| x ifTrue:[^ (y value)] ].
^ aLastBlock
You can use the
#caseOf:otherwise:message.Look for some sender of this message for some example.
But anyway if you want to use case statement you are not following the smalltalk-way-of-doing-things. Tell us what you want to achieve with your case statement so that we can show you some cleaner way to do it.