I added this as an example to the Slot package: 




This will be in the next update.


Very cool !!
A good example would be calculation based on other instance variables.
I took a guess...

Object subclass: #TT
slots: { #i. #j => VirtualSlot with: [ :o | o i + 1 ] }
classVariables: {  }
category: 'AAAA'

TT>> i
^i ifNil: [i:=0]

TT>> i:
    i: number
i := number

TT>> j
^j
In Playground...
(tt := TT new) inspect.
(tt i: 4) inspect.
 

Yes! The block can not refer to instance variables, so for more complex compilations
(or if one does not want to expose accessors), one might move the code to a ���compute��� 
method.

As an extension, it might be good to allow the Slot to be configured with a selector:

VirtualSlot with: #computeMyVar

This would just need some check in #read:.

Then of course, to speed things up one can do inlining by implementing #emitValue:, 
which could for the selector compile it to ���self computeMyVar���.

Marcus