Support for basic linear algebra on Array's

Oliver Hunt oliver at apple.com
Sun Nov 18 18:26:00 PST 2012


On Nov 18, 2012, at 6:17 PM, Matt Calhoun <calhoun137 at gmail.com> wrote:

> I believe that having a concise notation for linear algebra is an important feature of a programming language that can dramatically improve code readability, and furthermore that linear algebra is a powerful tool that has many applications in java script.  I would like to make the following two suggestions:
> 
> 1. Extend the "+" operator to work on Array's of numbers (or strings).
> 
> 2. Allow for scalar multiplication of Array's which contain only numbers.
> 
> Although there are many problems with a simple linear algebraic solution which arise in contexts where java script is a natural language of choice (for example WebGL), there are no simple ways to express these solutions in java script because the language itself creates a barrier to even basic operations such as subtracting two vectors, in the sense that the amount of writing it takes to express these operations obscures their mathematical content.  For more complicated linear algebraic work, the problem is quite severe.

Changing the behaviour of any of the basic operators on builtin/pre-existing types is essentially a non-starter.  + already has sufficiently, errr, "sensible" behaviour to be widely used on arrays.  Other operators don't really have any such "sensible" use cases, but changing their semantics on one kind of object vs. other kinds would be highly worrying.

(2) would also be a non-starter i feel: JS implicitly converts to number in all other cases, and if we made operator behaviour dependent on content type (in a nominally untyped language) I suspect we would very rapidly end up in a world of semantic pain, and another WAT presentation.

Also anytime i've seen someone propose * operating on arrays it rapidly becomes a flamewar between element-by-element multiplication and n-dimensional-dot-product.

ES6 provides comprehensions however that might make the world nicer for a lot of your use cases.

--Oliver

> 
> 
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss



More information about the es-discuss mailing list