2 ms·
Yes, I left that detail out for pedagogical purposes. As the other respondent wrote, it still works the same way but with parentheses, and the to:do: exists as
by mpweiher 9y ago
Yes, I left that detail out for pedagogical purposes.
As the other respondent wrote, it still works the same way but with parentheses, and the to:do: exists as a convenience.
In Objective-Smalltalk[1], I added | so you can do this without parenthesis:
(1 to:10) do: [ :i | stdout println:i. ].
can become:
1 to:10 | do: [ :i | stdout println:i ].
This is nice when you are constructing a statement interactively, for example on a command line and don't want to go back. It also makes things less convoluted when the chain gets longer. It also "fixes" the asymmetry that chaining works with unary messages but not with keyword messages.
Of course, the whole thing becomes even more elegant, IMHO, with a Higher Order Message (HOM)[2]:
stdout do println: (1 to:10) each.
YMMV.
[1] http://objective.st/ http://objective.st/
[2] https://en.wikipedia.org/wiki/Higher_order_message https://en.wikipedia.org/wiki/Higher_order_message