I've found it quite useful in Clojure/Script and I'm sure folks who have
encountered the feature in the ML derived languages would agree.

Indeed, all of the pattern-match-supporting functional languages
I've used also supported 'as'-patterns in some form ('var@pat' in Haskell, 'var as pat' in SML and variants, 'pat=pat' in Erlang, 'as pat var' in (little-known) KiR).

Those constructs are hard to search for on github (too many
false matches, though searching for 'as' in Standard ML code
might work), but I find them both useful and popular. Some of the usefulness comes from using pattern matching as a structural guard (checking the substructure conforms to a pattern, then just naming the substructure wholesale). I have no experience with a language that only destructures, without matching, but I would expect to use as-patterns with destructuring as well, increasingly so with upcoming
language constructs.

The main problems seem to be cover-grammars (construct
should be valid expression and pattern), and that the obvious
choice '=' is already taken for default parameters. A common generalization of as-patterns are conjunctive patterns (as in Successor ML or Erlang), which suggests 'pat&&pat' or perhaps '(pat,pat)' as alternative syntax.

Claus

_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to