Support for basic linear algebra on Array's

Brendan Eich brendan at mozilla.com
Sun Nov 18 22:49:23 PST 2012


Brendan Eich wrote:
> I agree that * or other operators should not be naively supported on 
> arrays, which are not value objects in any case. Any vector or matrix 
> value object would want sweet literal syntax, but it wouldn't be array 
> literal syntax, exactly. 

Just to elaborate on this. The syntax for vector and matrix literals 
would not be

let v = [0, 1, 2, 3];
let m = [[a, b, c, w], [d, e, f, x], [g, h, i ,y], [j, k, l, z]];

since arrays are not value objects, and nested arrays are not 2d matrices.

Rather, we'd have something like

let v = vector([0, 1, 2, 3]);
let m = matrix([[a, b, c, w], [d, e, f, x], [g, h, i ,y], [j, k, l, z]]);

or even (macros for new syntax)

let v = #vec[0, 1, 2, 3];
let m = #mat2d[[a, b, c, w], [d, e, f, x], [g, h, i ,y], [j, k, l, z]];

Or something even prettier. The point is that the new literal and 
operator forms would be lexically scoped hygienic macros, or built-ins 
prefiguring same that could be recast as macros later.

Then having operators just work on v and m would follow and not 
interfere with or affect any code not in scope.

/be


More information about the es-discuss mailing list