Generally low-level languages support struct
s, just what I want to hackishly define in AS3. We can do this on C#, but why do it? Because 3d positions are very common and it's boring to create an object for each 3d position just because you can't get a immutable structure in other languages freely, unless you don't want to declare a bunch of locals yourself.
struct Vec3f {
public double x;
public double y;
public double z;
}
class Test {
static void Main() {
Vec3f cam1 = new Vec3f();
Vec3f cam2 = cam1;
cam1.x = 10;
System.Console.WriteLine(cam1.x == cam2.x); // false
}
}
As you can see, Vec3f
is a immutable value type. But in JS, Lua, AS3 or whatever we usually can't have these kinds of immutable structures. Yep, we use objects, which are always garbage-collected AFAIK.
In AS3 I wanted to be able to meta-mark a class as *immutable*, but I don't see how if that's not supported anywhere. There's no existing ABC-level tool, so how?
[Immut] // or [Immutable]
class Vec3f {
var x: Number
var y: Number
var z: Number
}
var a: Location = new Location
var b: Location = a
a.x = 10
a.y === b.x // `true`, but should be *********`false`*********
// for `Vec3f`.