|
|
Log in / Subscribe / Register

"Structural pattern matching" for Python, part 1

"Structural pattern matching" for Python, part 1

Posted Aug 5, 2020 21:00 UTC (Wed) by NYKevin (subscriber, #129325)
In reply to: "Structural pattern matching" for Python, part 1 by mb
Parent article: "Structural pattern matching" for Python, part 1

Re the bitwise OR thing: I'm confused why they didn't just use logical OR there? In more complicated cases, you're very likely going to want short-circuit pattern matching (i.e. you probably should not be filling any variables on the "wrong" side of the logical operator, especially if they collide with the "right" side), so that seems like a better semantical fit for what they are trying to accomplish. Regardless, bitwise OR is needed for writing some constant values that cannot be expressed in any other way (see https://docs.python.org/3/library/enum.html#flag), so they certainly need to pick a different operator anyway.

I very much doubt there's a serious use case for "match the left pattern, but then if that pattern match succeeds *and* the thing you're matching against is falsey, throw out the whole match and start over with the right pattern instead" (which is the only other sensible interpretation of logical OR in this context). I also doubt anyone would intuitively interpret it that way, since that's just too ridiculous. So logical OR seems to me like the least-worst option here.


The LWN site is currently under high scraper load, so comment display has been suppressed for anonymous users. If you are a human, you may read the comments by clicking the button below:

Note: you can avoid this step in the future by logging into your LWN account.


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