Structs

Sam Ruby rubys at intertwingly.net
Tue Jun 1 18:29:25 PDT 2010


On 06/01/2010 09:15 PM, Waldemar Horwat wrote:
> Brendan:
>
> To clear up something that misled me when reading the first few messages
> of this struct thread:
>
> I assume that the proposal is that:
>
> const TA =
> Array.newTypedArray(fixed_length,
> Object.newStructType({x:"u32", y:"u32", z:"u32",
> r:"u8", g:"u8", b:"u8", a:"u8"}));
> let a = new TA(...);
>
> b = a[i];
> a[i].x += 1;
>
> Now b.x also reflects the new value of a[i].x; i.e. b is an alias, not a
> mutable copy.

That's a valid choice, but one that can't be applied 100% consistently. 
  For example, wouldn't the following create a mutable copy?

   a[0] = b;

I'll also assume that all aliases will pin the entire array for the 
purposes of garbage collection.

I'll still maintain that the choice that ECMA 334 takes, namely that the 
assignment to b in the example above, makes a mutable copy is a valid 
choice.

- Sam Ruby


More information about the es-discuss mailing list