David Mertz wrote: > I have a little bit of skepticism about the pattern matching syntax, for > similar reasons to those Larry expresses, and that Steve Dower mentioned on > Discourse. > Basically, I agree matching/destructuring is a powerful idea. But I also > wonder how much genuinely better it is than a library that does not require > a language change. For example, I could create a library to allow this: > m = Matcher(arbitrary_expression) > if m.case("StringNode(s)"): > process_string(m.val) > elif m.case("[a, 5, 6, b]"): > process_two_free_vars(*m.values) > elif m.case("PairNone(a, b)"): > a, b = m.values > process_pair(a, b) > elif m.case("DictNode"): > foo = {key, process_node(child_node) for key, child_node in > m.values.items()} > I don't disagree that the pattern mini-language looks nice as syntax. But > there's nothing about that mini-language that couldn't be put in a library > (with the caveat that patterns would need to be quoted in some way).
What you are proposing here is very similar in effect to executing pattern matching statements using `eval`. What is the advantage of implementing the pattern matching functionality in a library if the user interface for that functionality has the same pitfalls as `eval`? _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/E4KVS77FVES6KEH3DQRJMQDZO7WAXWLM/ Code of Conduct: http://python.org/psf/codeofconduct/