Re: The Pattern Matching Wildcard Is A Bad Idea

Yeah, that's it exactly. I see these two features - `_` as a joker in `match` statements and `_`as the last value produced by a shell - as incompatible, because you have to account for interferences between them, or face unexpected behaviors in code you run. I expect people to code like I do : first experiment a feature in a shell, then write a clean script that implements it cleanly. To debug that script, go back to the shell to run the script bit by bit, etc, etc. You'd expect code that runs in a shell to behave the same in a script, and vice-versa. But, if `_` is both a variable (shell) and a keyword (`match`), that 's not the case. You have to work around the problem, e.g. by reaffecting `_`. My fear is that most people (me included) will most likely forget this step when switching between a shell and a script. Le 02/06/2021 à 15:48, Damian Shaw a écrit :

But the discrepancy here is not the match statement, it's that "_" in REPLs doesn't behave like "_" in a script, if you are copying and pasting REPL code to a script this is something you already need to take into account. Also because REPLs have this feature only when the user doesn't bind to the name "_":
If the match statement didn't treat "_" as slightly special and bound the match to "_" then it would break this feature of REPLs. (apologies for mucking up the email addresses previously) On Wed, Jun 2, 2021 at 11:35 AM Alexis Masson <a.masson555@ntymail.com> wrote:

Reply to Alexis Masson: There's no way we can end up in an undefined state. Python just detects if _ is there, it doesn't use it's value. If it is there it's a wildcard pattern.

But the discrepancy here is not the match statement, it's that "_" in REPLs doesn't behave like "_" in a script, if you are copying and pasting REPL code to a script this is something you already need to take into account. Also because REPLs have this feature only when the user doesn't bind to the name "_":
If the match statement didn't treat "_" as slightly special and bound the match to "_" then it would break this feature of REPLs. (apologies for mucking up the email addresses previously) On Wed, Jun 2, 2021 at 11:35 AM Alexis Masson <a.masson555@ntymail.com> wrote:

Reply to Alexis Masson: There's no way we can end up in an undefined state. Python just detects if _ is there, it doesn't use it's value. If it is there it's a wildcard pattern.
participants (4)
-
Alexis Masson
-
Damian Shaw
-
Jelle Zijlstra
-
Shreyan Avigyan