Re:JavaScript Pattern Matching Proposal
by lpgauth on Wednesday April 25, 2018 @11:15AM
(#16922243)
No, have a look at Erlang! Pattern matching is one of it's most powerful feature.
[ Parent
| on HN ]
Re:JavaScript Pattern Matching Proposal
by gmfawcett on Wednesday April 25, 2018 @12:08PM
(#16922935)
And Prolog as well, which strongly influenced Erlang's design. (The original Erlang was written in Prolog.)
I agree with the sentiments of some of the other commenters -- it's much less troublesome to match on tuples (Erlang) and predicate clauses (Prolog) than it is to match on JavaScript objects. With tuples/clauses, the constructor syntax mirrors the pattern matching syntax, so it's trivial to read the code at a purely syntactic level to debug pattern matching issues, and this would simplify automatic static analysis as well. As soon as you can add "fields" to an object at arbitrary (non-local) points in the code, local syntactic analysis becomes intractable.