Support for basic linear algebra on Array's
douglas at crockford.com
Mon Nov 19 00:23:12 PST 2012
On 2012-11-18 10:49 PM, Brendan Eich wrote:
> 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.
Or we could put more methods on Array.prototype like .add(a), .mul(a),
.dot(a), .cross(a). And more functions on Array like .identity(n) and
.matrix(m, n, value).
More information about the es-discuss