On Tue, May 19, 2015 at 12:24 PM, Steve Fink <[email protected]> wrote:

> That visually collides with destructuring for me.
>
> let [a, b] = foo();
> let {a, b} = foo();
> let f(a, b) = foo(); # Very different
>
> I almost expect that last one to use f as a custom matcher of some sort,
> given the previous two.


Well *there's* an interesting proposal.  As I understand it, this corner of
the grammar is free, so custom matchers would be a possibility here.

I can imagine some interesting uses for custom data types, eg:

let pair(a, b) = foo(); // like `let {head, tail} = foo();` but with custom
type checking.
let polar(radius, angle) = point(1, 2); // custom matcher can convert
between coordinate respresentations

or even build a simple matching case statement for a recursive decent
parser:

let for_statement(init, cond, incr) = input_text;

Does that spark ideas in anyone else?
  --scott
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to