Novel operator syntax
tristan at senseplatform.com
Tue Oct 29 11:23:32 PDT 2013
On Tue, Oct 29, 2013 at 10:37 AM, Tab Atkins Jr. <jackalmage at gmail.com>wrote:
> 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
> > 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
> > 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
> > 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
> > choice. The technical community would prefer dots. I know these
> > all having meanings alone, but does .op introduce any ambiguity? Are
> > other lightweight options?
> Yes, .op is completely unusable. "foo .bar" is identical to "foo.bar".
Sorry, at most I'm only proposing every *existing* operator prefixed by .,
not new operators. So things like
.+, ./, .*, .-., .%, .==, .!=, .>, .<, etc. These would be called dot
operators. This is all that's required by the
technical computing use case.
There's a question of whether to allow arbitrary operators, which would
require a new symbol obviously. I personally don't think arbitrary
operators are worth the noise and complexity. I'd leave this issue to
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss