(Jakub, next time please trim the original post from your quote to what's necessary.)
On Wed, Jun 24, 2020 at 9:11 AM <ja...@stasiak.at> wrote: > Wow, I totally didn't see this coming, not after seeing what seems like a > lot of rejected ideas on this topic (there was at least one PEP already > that proposed this, right?). I have to admire the authors' determination to > write such a lengthy and (from skimming it) complex and comprehensive > proposal *and* providing a reference implementation on top of that, the > amount of work (including internal bikeshedding) must've been substantial. > > Needless to say it's +1 from my humble person, big time, and I wouldn't > want the comment below to detract from that. > > So, now for the one thing that makes me unhappy: the rejected idea to make > it an expression. In my short experience with pattern matching, mainly in > Rust, roughly half (very vague estimate) of its usefulness came from it > being an expression. It's even small things like > > let i = match i { > 9 => 10, > 10 => 9, > _ => i, > }; > > and > > let mut file: Box<Write> = match filename.as_ref() { > "-" => Box::new(io::stdout()), > _ => Box::new(File::create(filename).expect("Cannot open file for > writing")), > }; > > and it adds up. I'm not sure how to approach this with Python syntax and > I'll think about this, but I feel that it'd be a huge missed opportunity to > not have this. > We considered it, but it simply doesn't work, for the same reason that we haven't been able to find a suitable multi-line lambda expression. Since Python fundamentally is not an expression language, this is no great loss -- you simply write a match statement that assigns a value to the variable in each branch. Alternatively, the match could be inside a function and each block could return a value. -- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
_______________________________________________ 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/FI5IYTCVOMR7CO3W6FDPRZYLYJNNU745/ Code of Conduct: http://python.org/psf/codeofconduct/