Michael van der Gulik
mikevdg at gmail.com
Wed Mar 17 20:02:32 UTC 2010
On Thu, Mar 18, 2010 at 3:26 AM, Randal L. Schwartz
<merlyn at stonehenge.com> wrote:
> Has anyone looked at, proposed, implemented object immutability?
> Obviously, it would require a VM change.
It doesn't really need a VM change. I'll be implementing immutability
in SecureSqueak, and most (or all?) literals in a CompiledMethod will
be made immutable.
The pattern I use is that setters in immutable objects are implemented
baked ifFalse: [ someValue := x ]
ifTrue: [ throw an error or something. ].
"baked" is an instance variable.
| result |
result := super initialize.
baked isNil ifFalse: [ ^ error of some sort. ].
baked := false.
baked := true. " i.e. not nil."
In SecureSqueak, direct invasive object access using basicAt:put:,
at:put: and so forth will be disallowed.
More information about the Squeak-dev