Variatic Smalltalk Features

Does Smalltalk (especially Squeak / Pharo) have some form of variational function?

I just read about how to create my own control statuses in smalltalk, and although I am a big fan of ifTrue: ifFalse: it was hard for me to find a good way to implement arbitrary if, if more, if else, ..., else who think about it how useful the Variadic functions are for implementing case statements. Sort of

false class

ifTrue: aBlock (... elseIf: aBoolean then: aSecondBlock ...) else: aLastBlock

vArgList pairsDo: [:x :y| x ifTrue:[^ (y value)] ].
^ aLastBlock
+5
source share
3 answers

You can use the message #caseOf:otherwise:. Look at some sender of this message for some example.

, case, . , , , .

+1

Smalltalk, , . &rest, Common Lisp.

, , BlockClosure>>valueWithArguments:, .

Compiler . , with: :

() ifTrue: aBlock elseIf: aBoolean : aSecondBlock : anotherBoolean : aThirdBlock

+3

, , , case, case.

- . , . , , -, , , .

, . .

. , . , , .

.

-, ifTrue: ifFalse: - . , , , , .

, #doTheNextThing. , , ( , 3 ( 30, ), , .

, . , , , , , , .

, , AFAIK . , .

In addition, creating 3 classes may seem like a big deal to some, but it is not. Any noob can add 3 empty classes to blink, but only the right expert will remember how the case statement was created in the old code, how it was made. And if you are wildly optimistic, it will take minutes to remember that you all know what to do next. Think about it.

+1
source

All Articles