let function
Brendan Eich
brendan at mozilla.org
Tue May 19 20:03:18 UTC 2015
C. Scott Ananian wrote:
> On Tue, May 19, 2015 at 12:24 PM, Steve Fink <sphink at gmail.com
> <mailto:sphink at gmail.com>> 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?
Sure, and we've had pattern matching on the agenda for a while (distinct
from destructuring in ES6: refutable match, richer pattern language).
http://wiki.ecmascript.org/doku.php?id=harmony:refutable_matching
(arossberg: anything newer on github?)
http://wiki.ecmascript.org/doku.php?id=strawman:pattern_matching (older
strawman from dherman)
I agree that `let f(x) = y` encroaches confusingly on pattern matching,
not let-function declaration.
/be
More information about the es-discuss
mailing list