[Python-ideas] Match statement brainstorm

Stephen J. Turnbull stephen at xemacs.org
Wed May 25 22:34:18 EDT 2016


Nikolaus Rath writes:

 > Or maybe:
 > 
 > if <thing> ...
 >    matches <matcher>:
 >       pass
 >    matches <matcher>:
 >       pass
 > 
 > Where "..." is an actual syntactic element that replaces the ":" in a
 > regular if.

Interesting, but I don't like it because (1) ":" is *the* compound
syntax indicator in Python, (2) "..." looks like somebody forgot to
fill in a blank, *and it should* look that way, (3) "matches" is too
close to "match" (which is a stdlib identifier), and it's an
identifier I have used, and (4) it's an additional keyword.

Leaving aside the spelling quibbles, following "if" I would "see"
"matches" as an operator, and want to write

    if <thing> matches <matcher>:
        pass
    elif <thing> matches <matcher>:
        pass

and I'm back in "if ... elif ... else ..." land.  I don't really see
much advantage to your particular spelling, as to me it doesn't have
the connotation that Paul requires (correctly, IMHO) of a single
"subject" tested against multiple "predicates".  It just "looks wrong"
to me.

IMHO, YMMV, etc.  It *is* interesting, I am trying to contribute to
discussion, not end it.  My mind could be updated. :-)





More information about the Python-ideas mailing list