If you wanted to take a mutable object and make it immutable and be able to go back again to mutable, how could you do that?
In particular the part that has me as a smalltalk beginner stumped is how to disallow any messages that would result in a state change while still allowing messages that only read state.
Do you have to handle on a message by message basis? ( Eeek lots and lots of work ) Or is there something you could work into a superclass and use in its descendents? ( ideal for what I need. )
"Sean" == Sean Allen sean@monkeysnatchbanana.com writes:
Sean> If you wanted to take a mutable object and make it immutable and be able Sean> to go back again to mutable, how could you do that?
Squeak doesn't have that sort of capability. The immutability of a few classes is because the VM recognizes them specially, and not available at the programmer level without modifying the VM.
Other Smalltalk VMs are different. I think both VisualWorks and GemStone/S have primitive bits on an object to be informed when a mutation might be attempted.
You can simulate that *mostly* in Squeak by using a "proxy" object that intercepts all messages and looks for the dangerous ones, but that's gonna be a bit hard to do, and won't be aware of any new code that might call the mutating primitives directly. (*Any* method can call a primitive.)
Am 02.10.2008 um 08:50 schrieb Sean Allen:
If you wanted to take a mutable object and make it immutable and be able to go back again to mutable, how could you do that?
What is your use case?
In particular the part that has me as a smalltalk beginner stumped is how to disallow any messages that would result in a state change while still allowing messages that only read state.
Do you have to handle on a message by message basis? ( Eeek lots and lots of work ) Or is there something you could work into a superclass and use in its descendents? ( ideal for what I need. )
Well, it's hardly a beginner's topic, but you could make your class use a modified compiler that protects instance variable assignment by the check of an "immutable" flag.
This is basically how Avi's WriteBarrier works.
- Bert -
On Oct 2, 2008, at 1:18 PM, Bert Freudenberg wrote:
Well, it's hardly a beginner's topic, but you could make your class use a modified compiler that protects instance variable assignment by the check of an "immutable" flag.
This is basically how Avi's WriteBarrier works.
I'm going to have to load that into an image and take a look at that. The description is intriguing.
On Oct 2, 2008, at 1:18 PM, Bert Freudenberg wrote:
If you wanted to take a mutable object and make it immutable and be able to go back again to mutable, how could you do that?
What is your use case?
use case.
system needs to track changes to itself.
one option that has come up is...
linked list of different 'versions' of same object. head is the live object. everything else past versions.
want to mutate object? you have to 'unlock'. unlocking gives you a new copy and updates the linked list, allowing all the accessors that mutate state to work.
when locked, calling one of those accessors would result in an error. but when locked, read access still needed.
if i can find a way to put this in a superclass and have children get the functionality w/o doing anything else, then i really like it.
it cuts down on the 'real' programming as there are many classes and many messages that need said functionality and honestly, the disk space etc for the objects isnt a concern.
there are other options that have been looked at but all require mucking about with each different class which ideally, we want to avoid.
On Thu, Oct 02, 2008 at 02:55:34PM -0400, Sean Allen wrote:
On Oct 2, 2008, at 1:18 PM, Bert Freudenberg wrote:
If you wanted to take a mutable object and make it immutable and be able to go back again to mutable, how could you do that?
What is your use case?
use case.
system needs to track changes to itself.
one option that has come up is...
linked list of different 'versions' of same object. head is the live object. everything else past versions.
want to mutate object? you have to 'unlock'. unlocking gives you a new copy and updates the linked list, allowing all the accessors that mutate state to work.
when locked, calling one of those accessors would result in an error. but when locked, read access still needed.
if i can find a way to put this in a superclass and have children get the functionality w/o doing anything else, then i really like it.
heh. I'm making something that creates a new object version whenever an ivar is changed. I'm using tweak's fields and compiler to do it, so it will only work in a Croquet image. Not to mention that I've just barely started. The code is at
http://croquet-src-01.oit.duke.edu:8886/RayTracing/Quansi-Core-mtf.10.mcz
Am 02.10.2008 um 12:44 schrieb Matthew Fulmer:
On Thu, Oct 02, 2008 at 02:55:34PM -0400, Sean Allen wrote:
On Oct 2, 2008, at 1:18 PM, Bert Freudenberg wrote:
If you wanted to take a mutable object and make it immutable and be able to go back again to mutable, how could you do that?
What is your use case?
use case.
system needs to track changes to itself.
one option that has come up is...
linked list of different 'versions' of same object. head is the live object. everything else past versions.
want to mutate object? you have to 'unlock'. unlocking gives you a new copy and updates the linked list, allowing all the accessors that mutate state to work.
when locked, calling one of those accessors would result in an error. but when locked, read access still needed.
if i can find a way to put this in a superclass and have children get the functionality w/o doing anything else, then i really like it.
heh. I'm making something that creates a new object version whenever an ivar is changed. I'm using tweak's fields and compiler to do it, so it will only work in a Croquet image. Not to mention that I've just barely started. The code is at
http://croquet-src-01.oit.duke.edu:8886/RayTracing/Quansi-Core-mtf.10.mcz
That seems to be en vogue right now ... see
http://www.vpri.org/pdf/rn2008001_worlds.pdf
- Bert -
beginners@lists.squeakfoundation.org