3 ms·
1 to: 5 do: [echo :x] in smalltalk translate to: 1 to: 5 do: [:x | Transcript show: x ] 1(smallInt object) receive message 'to' with parameter 5 (smallInt obj
by Chyzwar 10y ago
1 to: 5 do: [echo :x]
in smalltalk translate to:
1 to: 5 do: [:x | Transcript show: x ]
1(smallInt object) receive message 'to' with parameter 5 (smallInt object) return numeric range, then you send 'do; message with parameter being a block that evaluate for each element in range.
Smalltalk is about objects and message passing. Spry only use Smalltalk syntax.
- ithkuil 10y agonitpick; that what you described is: (1 to: 5) do: [:x | Transcript show: x ] there is actually a to:do: method in the Number class, for example see the GNU smalltalk documentation: https://www.gnu.org/software/smalltalk/manual-base/html_node/Number_002dshortcuts-and-iterators.html#Number_002dshortcuts-and-iterators https://www.gnu.org/software/smalltalk/manual-base/html_node...
- Chyzwar 10y agobut internally to:do: is implemented as from:to:by: and do: with is almost the same.
- gokr 10y agoWell, Spry is much more Smalltalk than "only use Smalltalk syntax". But I have an entire article being written on that subject :) And no, your description of how it works in Smalltalk is wrong - #to:do: is implemented in the receiver (1). In Spry we are calling an infix function named to:do: and the only real difference to Smalltalk in this case is the fact that the dispatch of to:do: is not polymorphic. But as I described in other comments I am working on polymorphic functions as a way to reach similar abstraction levels.
- Chyzwar 10y agoThe thing is that Smalltalk do not have language constructs like loops or conditionals ifs/switch. Smalltalk also do not have functions only methods. There are only objects and messages. Your infix functions would need to live somewhere probably in global scope with makes then no different than language constructs. I would love to see new Smalltalk implementation that is not a Walled Garden. Making a Smalltalk impure is not a way foward imo. You work is interesting but what we need is Smalltalk VM on modern back-end like LLVM and better concurrency.
- gokr 10y agoSpry does not have these builtin either, they are all functions. In fact, even assignment is, which makes Spry even more minimal then Smalltalk in this sense. I know Smalltalk VERY well, and Spry is trying to experiment. I think polymorphic functions can be just as powerful as a class based model, even more so, and still feel similar. But i need to write examples to show it.