4 ms·
Smalltalk (and Dart) also have "cascading" which is method chaining with special supporting syntax e.g. in ST you'd send four different messages to the same obj
by riffraff 2y ago
Smalltalk (and Dart) also have "cascading" which is method chaining with special supporting syntax e.g. in ST you'd send four different messages to the same object with something like
scene add: sprite;
add: otherSprite;
setBackGround: stage;
start
I'm not sure if it matches the "reuse values from previous computation" but it should since messages will affect the object, you just don't have local variables.
- zelphirkalt 2y agoIt is using ';' instead of parenthesizing the messages to the objects, correct?
- klibertp 2y agoIn Smalltalk, `;` does two things: terminates the current message (EDIT: while ignoring its return value) and propagates the target object of the current message as a target for the following message. So this: scene add: sprite; add: otherSprite; setBackGround: stage; start is equivalent to: scene add: sprite. scene add: otherSprite. scene setBackGround: stage. scene start. In Dart, they use `..` prefix instead of `;` postfix: https://dart.dev/language/operators#cascade-notation https://dart.dev/language/operators#cascade-notation var paint = Paint() ..color = Colors.black ..strokeCap = StrokeCap.round ..strokeWidth = 5.0; You can model this with monads easily, but it's just one, very limited application of them - monads are much more general.
- zem 2y agovisual basic has the `with` statement for that https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/with-end-with-statement https://learn.microsoft.com/en-us/dotnet/visual-basic/langua...
- elcritch 2y agoNim has a similar `with` for the same use case. It can be handy!