3 ms·
> They've reinvented OCaml / SML pattern matching. I don't think so. ML pattern matching is statically machine checkable for exhaustiveness. P6 matching is dyn
by raiph 7y ago
> They've reinvented OCaml / SML pattern matching.
I don't think so. ML pattern matching is statically machine checkable for exhaustiveness. P6 matching is dynamic.
Aiui what they've done is generalized matching.
This includes features traditionally associated with pattern matching. But also any other match/destructure/bind operation.
A field of a match might build a parse tree or AST.
(Perl 5 did a simple small scale flat assignment approach to this; a statement could assign variables to selected elements of an array of captures extracted from a string by a regex. Perl 6 scales this up to turing complete parsing and AST generation involving huge numbers of nodes.)
One can match an arbitrary predicate. That's what the `* > 1` is. It's not a pattern.
Any value or variable can be matched against any value or variable. (Not just literals.)
Matching is "smart". For example:
say DateTime.new('2020-01-01T01:01:01Z') ~~ Date.new('2020-01-01')
displays True.
And it can all be destructured (with a fairly sophisticated range of options) and bound as part of the match.