I\'m doing research in Smalltalk reflection, and I was wondering if it was possible to extend an individual object like that would be possible for instance in Ruby. With thi
Having instance specific behavior in Smalltalk basically involves changing a pointer class and a primitive call. The "Debugging Objects" article by Bob Hinkle, Vicki Jones, and Ralph E. Johnson, published in The Smalltalk Report, Volume 2#9, July-August 1993, contains all the explanations.
I have ported the original Lightweight classes code from the version released in 1995 by Bob Hinkle for VisualWorks 2.0. The VisualWorks source includes code divided in three packages named "ParameterizedCompiler", "Breakpoint" and "Lightweight". The reason of this division was generated by the desire of having separate and re-usable functionality. All of them have separate articles in OOP journals.
My Squeak/Pharo port contains an "Instances Browser", based on the OmniBrowser (and more documentation here) framework, which lets you browse and modify the instances adding the Lightweight behavior through the classic Smalltalk Browser UI. It would work in latest Squeak 4.x versions with little or no effort. Unfortunately the infrastructure of Pharo changed substantially from versions <= 1.2, therefore it may need some work to work it latest versions.
In VisualWorks, due to the deep changes in the VisualWorks GUI from 2.0 to 7.3, most of the tools to manage the lightweight classes were not included. If someone is interested, I can upload the parcel for VW 7.3
A basic script to test the lightweight classes features is:
| aDate |
aDate := Date today.
aDate becomeLightweight.
aDate dispatchingClass
compile: 'day ^42'
notifying: nil
ifFail: [self error].
aDate day inspect