[Newbies] 'locking' an object

Randal L. Schwartz merlyn at stonehenge.com
Thu Oct 2 15:58:36 UTC 2008


>>>>> "Sean" == Sean Allen <sean at 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.)

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion


More information about the Beginners mailing list