Novel operator syntax

Tristan Zajonc tristan at senseplatform.com
Tue Oct 29 10:01:22 PDT 2013


Following up on the discussion about operator overloading, what are viable
options for introducing novel infix operators or a class of
extended/prefixed operators?

For motivation, I along with some others have implemented a MATLAB/R like
environment for JS. We've written a compile-to-js language that supports,
among other things, operator overloading and prefixed operators,  However
we'd much prefer to follow ES6/7 and ideally avoid the need for a
compile-to-js language entirely, at least in the future.  Without going
into the details, prefixed operators are useful for defining objectwise and
elementwise operations on matrices, which is a core type in technical
computing (see Julia, MATLAB, Mata, Python PEP 225).

Assuming JS allowed prefixed operators:

1. What would be the most likely syntax?  As a reference, Julia and Matlab
use dots, a .+ b.  Stata's Mata languages uses colons, a :+ b.  PEP225
proposes tildle a ~+ b.  R uses %infix% but this is widely viewed as a bad
choice.  The technical community would prefer dots.  I know these prefixes
all having meanings alone, but does .op introduce any ambiguity?  Are there
other lightweight options?

2. Is there a preferred class literal syntax?  I believe the proposed value
object syntax would be perfect if extended to classes as well.

3. Can this be done prior to macros?  It may be my narrow matrix centered
view, but I do not believe there's a compelling need for arbitrary infix
operators in technical computing if it introduces additional difficulties.

With ES6 and these operators I believe JS/NodeJS could easily take over the
technical and statistical computing domains.

Tristan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20131029/45ee5838/attachment.html>


More information about the es-discuss mailing list