Structs

Sam Ruby rubys at intertwingly.net
Thu May 27 13:10:41 PDT 2010


On 05/27/2010 03:05 PM, Brendan Eich wrote:
> On May 27, 2010, at 11:38 AM, Sam Ruby wrote:
>
>>> Well-supported arrays of structs (as schemas) might be a satisfactory
>>> compromise. Consensus emerging around that solution.
>>
>> Structs in ECMA-334 are value types, and consist of members that also
>> are value types. Would structs in future revisions of ECMA-262 share
>> these characteristics?
>>
>> Is it fair to assume that there would end up being a more richer set
>> of primitives to select from when composing a struct than simply
>> "object", "boolean", "number", "string" and the like? Again, ECMA-334
>> defines the following:
>>
>> http://en.csharp-online.net/ECMA-334:_11.1.5_Integral_types
>>
>> Would something similar be envisioned for ECMA-262?
>
> No, we did not envision adding more primitive types, type annotations,
> conversion rules, and first-class struct declarations.
>
> Something more like
>
> 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(...);
>
> ... a[i].x ...

I'll note that with newStructType one could define a 128 bit quantity 
for representing a complex number.  That coupled with something like the 
following proposal would enable a complete set of complex arithmetic 
operators to be supported:

https://mail.mozilla.org/pipermail/es-discuss/2009-January/008535.html

- Sam Ruby


More information about the es-discuss mailing list