Novel operator syntax

Tab Atkins Jr. jackalmage at gmail.com
Tue Oct 29 10:37:40 PDT 2013


On Tue, Oct 29, 2013 at 10:01 AM, Tristan Zajonc
<tristan at senseplatform.com> wrote:
> 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?

Yes, .op is completely unusable.  "foo .bar" is identical to "foo.bar".

~TJ


More information about the es-discuss mailing list