Operators overriding

Coroutines coroutines at gmail.com
Mon Dec 28 18:26:35 UTC 2015


On Mon, Dec 28, 2015 at 9:55 AM, Bradley Meck <bradley.meck at gmail.com> wrote:
> Who would think not knowing what `a+b` could do as a pitfall? /s
>
> I am not a big fan of overloading though, since it presents more mental
> complexity as they map to functions without looking like function calls.

>From the Wikipedia page on ecmascript it seemed like operator
overloading was already a for-sure planned feature of ES7, just not
fleshed out in a spec.  I personally do love operator overloading - I
am used to it from Lua and Python and I think it can be quite nice.
Especially for making PEG combinator stuff:

term = Any(1) // any 1 character
whitespace = Range(CharSet(' \t'), 1, Infinity) // space or tab,
repeated 1 or more times
indented_term = whitespace + term // will match: '          x'

result = indented_term.parse('    text...')

Okay this is a bad example.  But when you're building a grammar
description from objects it can be quite fun to make use of operator
overloading for a much cleaner description - somewhat like a
domain-specific language (DSL) within JS.  LPeg in Lua and PyPeg in
Python make this rather pleasant.

Anyway, I suspect it won't matter what syntactic features Javascript
gains once WebAssembly gets adopted.  We already have the fundamentals
like inheritance in place so that any language can compile to a
WebAssembly AST and run as one would expect.


More information about the es-discuss mailing list