On 03 Jul 2014, at 13:15, Tudor Girba <[email protected]> wrote:
> I cannot wait to get to play with this.
>
> Btw, is it possible to have a slot per object? Or are slots only part of the
> class definition?
>
They are part of the class definition. The idea is to get lots of power
*without* changing the underlying object model…
> I am thinking of several performance optimization scenarios that I saw in
> Moose where we need to store a temporary value in an object as a cache as
> part of a larger computation. Typically, for things like this you create
> another structure in between, but the problem with that approach is that you
> lose object identity and things become immediately too complicated.
>
> If we would have a slot per object, we could use this mechanism in such a
> way. I think there is a class of scenarios that can be simplified
> significantly. If per object is not possible, we could somehow think of a
> special slot that would hold a dictionary with instances as keys.
You could do a slot that saves object state in a such a dictionary, adding such
a slot to the class would mean that you would not need to #become all the
instances… but else it is the same
as adding an instance variable reflectively in standard smalltalk, with the
downside that it would be slow and memory intensive.
So the better way is to use the same trick that is possible now: anonyous
subclass, add the slot there, change class of your object to that anonymous
class.
We should add a nice API on Object (#addInstanceSlot: or something that hides
the whole complexity and makes it easy to use…)
I want to look at instance specific mechanisms later, after a) Slots are there
and b) we have MetaLinks for both Slots, Globals and AST nodes...
Marcus