On 15 February 2017 at 18:45, Sven Van Caekenberghe <sven@stfx.eu> wrote:
A custom extension is soo easy to do and will probably fit your expectations better. It would not be much more work than listing/indicating which attributes you want to display.
My original thought was to use method pragmas to tag the methods to be inspected. This would also provide a hint as to what the author was thinking when the code was written (that the method is more of an attribute of the object than an operation that can be performed). On 15 February 2017 at 20:56, Ben Coman <btc@openinworld.com> wrote:
Would it be feasible to have a "CalculationSlot" that was read only, and each time it was read it performed the calculation?
I have read about Slots but hadn't looked in to them before, more below. On 16 February 2017 at 00:18, denker <marcus.denker@inria.fr> wrote:
I added this as an example to the Slot package:
https://pharo.fogbugz.com/f/cases/19709/add-example-ComputedSlot
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
Many thanks for providing such a detailed example and especially getting it in to the base image so quickly (that's a record in my experience). At the moment I think that your suggested extension of configuring the slot with a selector may be better than supplying a block as it makes the code easier to read, i.e. the code is located in the method definition and not embedded the class definition. My inclination is to create a new type of slot, InspectorSlot or MethodSlot, that operates as you suggest rather than extending ComputedSlot. If you'd like this included, let me know, along with any suggestions for a better name, and I'll put together the fogbugz issue and slice. Thanks again, Alistair