The latest Industry Misinterpretations which I missed made me remember something. Dave and James were talking about the way the class and metaclass hierarchies work in Smalltalk and jokingly talked about how .NETers might get exposed and confused by it with VistaSmalltalk.
This made me remember one of the reasons why I've been thinking about making a programming language for years (which will probably never happen, but one can dream!). The main feature I wanted in a new language was to be more like Self and IO - be prototype based. Use slots that are indistinguishable between behavior and values at runtime. Self demonstrated how powerful this idea can be.
The more my friend David and I talked about this stuff, the more we started figuring out how it could be implemented. Eventually, David decided he liked classes more than prototypes.. I still prefer prototypes to classes.. so my brain is still ticking over on the problem. The basic crux of a language like this is speed - you need a Polymorphic Inline Cache (PIC) to make it run fast and it's hard to do that because you can have more than one slot - multiple inheritence. How do you do a PIC if you have no type?
So the basic idea to get around this is to make a type object that represents the combination of shape and behavior for each instance and share them when two instances happen to get the same combination (this will be very common). So, this essentially means you have objects with types - which looks just like a regular Smalltalk object.
Something clicked in my brain - why not use the VisualWorks VM with its advanced JITting.. and make the language run side by side with Smalltalk so you get the advantage of all those libraries that already exist.
Okay, so I need to prove some things to see if that can work. First of all - can we create objects that have behavior instead of a class. YES! See the package BareBehavior in public store - you can then do something like this:
| fakeClass fakeInstance | fakeClass := BareBehavior new. fakeInstance := fakeClass new. fakeInstance class == fakeClass
Now that we know that we can make our own kind of behavior - how would we dynamically change shape? Well, unfortunately the VisualWorks VM cannot do dynamic shape changing of an object unless you change the shape of the class - which we don't really want to do since we're going to be sharing those "types" between objects. We want to change the type to another shaped type while its running. The easiest way to do that is to make a new object with the new type and copy the state over. Not idea - but it works. VM designers - a thought for you perhaps?
Finally, Travis threw the gauntlet down again.. what about an Object that has no class - or more specially, an Object that is its own class. YES! - We can do that too. See the package IamMyOwnClass in public store. Now we can prove it with code like this:
"Demonstrates that the class of fakeInstance is itself" | fakeClass fakeInstance | fakeClass := BareBehavior new. fakeInstance := fakeClass create. fakeInstance class == fakeInstance. "Demonstrates that we can add new behavior to fakeInstance and then call it" | fakeClass fakeInstance | fakeClass := BareBehavior new. fakeInstance := fakeClass create. fakeInstance methodAt: #yourself put: (Object compiledMethodAt: #yourself). fakeInstance yourself class == fakeInstance
Enjoy the paradoxes and impossibilities!