|
|
Log in / Subscribe / Register

An overview of structural pattern matching for Python

An overview of structural pattern matching for Python

Posted May 4, 2022 18:21 UTC (Wed) by jezuch (subscriber, #52988)
In reply to: An overview of structural pattern matching for Python by epa
Parent article: An overview of structural pattern matching for Python

> I don’t think there is any language that can easily add new keywords.

There's Java :) Kind of, at least. They've recently added a couple of keywords by using a trick: they're context-dependent. See for example "yield" in the new enhanced switch. The latest proposals of pattern-matching switch go even further, adding "when" keyword as a case guard.

The current design is here: https://openjdk.java.net/jeps/427 As a bonus you can compare it with what is described in the article ;)


to post comments

An overview of structural pattern matching for Python

Posted May 5, 2022 15:22 UTC (Thu) by kokada (subscriber, #92849) [Link] (1 responses)

Well, from the looks of the text it does looks to me that `match` in Python s also context-dependent. The text even gave an example on how you could have both a variable called `match` and a `match` statement one after another (with the amusing resulting `match match:`).

An overview of structural pattern matching for Python

Posted May 7, 2022 1:48 UTC (Sat) by smitty_one_each (subscriber, #28989) [Link]

Right. "Soft" keywords, due to the PEG parser.


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds