4 ms·
Pretty sure this was taken from Smalltalk, which uses the semicolon as the cascade. So a b c d. sends c to the result of sending b to a, and d to the t
by mpweiher 5y ago
Pretty sure this was taken from Smalltalk, which uses the semicolon as the cascade.
So
a b c d.
sends c to the result of sending b to a, and d to the the previous result etc.
a b; c; d.
Sends b, c, and d to a. This is often indicated visually:
a b;
c;
d.
- musicale 5y agoSemicolon/method cascade is one of my favorite bits of Smalltalk syntax. I'm a bit neutral on returning self (either explicitly or implicitly), although it enables left-to-right pseudo-expressions like 1 + 2 * 3.
- mpweiher 5y agoI am also fond. And interestingly, the cascade actually separates keyword messages nicely without having to use brackets, which normal messaging does not. So: a foo:2; bar:4. This sends foo: and bar: to a. But you can't do that without the cascade: a foo:2 bar:4. That's not bar: sent to the result of a foo:, that's foo:bar: sent to a. For normal messages you have to use brackets: (a foo:2) bar:4. Which is ugly and asymmetrical with respect to cascades. So in Objective-S, I introduced the pipe for message chaining: a foo:2 | bar: 4. IMHO, this works both visually and semantically, because you are "piping" the result of "a foo:2" into the message expression " bar: 4", as the receiver.