[Python-ideas] Re: Add switch-case statements in Python
Got it ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/SB7KKXMYBRYKRX25GDKVGO5OROZWW7EY/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Add switch-case statements in Python
I'm not sure if you're reading the right document, but PEP 634 refers to 636 in its second paragraph On Tue, 4 May 2021, 19:56 Shreyan Avigyan, wrote: > Ok. Now I'm able to understand. PEP 634 should have a reference to PEP 636 > or else it's pretty hard to understand because the syntax section > demonstrates PEG implementation of this. > ___ > Python-ideas mailing list -- python-ideas@python.org > To unsubscribe send an email to python-ideas-le...@python.org > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > Message archived at > https://mail.python.org/archives/list/python-ideas@python.org/message/APKN7AV5TLLNSO3EHLK2MBEEBCB5NMEF/ > Code of Conduct: http://python.org/psf/codeofconduct/ > ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/S5TJBM3TD4X6GUSJI5ERITIZIDCX5536/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Add switch-case statements in Python
This thread is closed therefore. (It was mistakenly opened due to misunderstanding.) ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/J5CXG2ITBLWGT2ZUWMXVGTU5DU442Q6Q/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Add switch-case statements in Python
Ooops...Didn't notice it. Anyway this thread is considered closed. ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/DQ6BN5I5ZUYRYBWWBD6LCSNQ5PDHP46S/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Add switch-case statements in Python
Ok. ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/UFGJ2TJI3IMOVBJUBPVXCPQOBVVCENXL/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Add switch-case statements in Python
It does, right at the top: https://www.python.org/dev/peps/pep-0634/#abstract ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/MID6BMSEBJQRZAXYWQMR5J6MGYQI7NEQ/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Add switch-case statements in Python
Ok. Now I'm able to understand. PEP 634 should have a reference to PEP 636 or else it's pretty hard to understand because the syntax section demonstrates PEG implementation of this. ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/APKN7AV5TLLNSO3EHLK2MBEEBCB5NMEF/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Add switch-case statements in Python
I'm confused. PEP 634 is about switch statements in Python or PEG? ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/JSZEXJQSAJFUZTF4PWO35UQZGVH2X56X/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Add switch-case statements in Python
> Isn't PEP 643 for PEG grammar pattern matching? (I'm talking about > switch statements in Python) I think you are referring to PEP 634, the one I linked to. I suggest you read it (and the other link I sent). I copy from PEP 636, marked as a sort of "tutorial" for PEP 634: ``` A match statement takes an expression and compares its value to successive patterns given as one or more case blocks. This is superficially similar to a switch statement in C, Java or JavaScript (and many other languages), but much more powerful. The simplest form compares a subject value against one or more literals: def http_error(status): match status: case 400: return "Bad request" case 404: return "Not found" case 418: return "I'm a teapot" case _: return "Something's wrong with the Internet" ``` - DLD ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/IGRJ5W6K3G6B5AM4JRHLYRTLPG2FIIKP/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Add switch-case statements in Python
> Most of programming languages out there have switch-case statements. > Python doesn't have support for switch-case statements though. > switch-case statements can sometimes be nice and tidy and sometimes it > may be a horrible nightmare. But that also applies to if-elif-else > statements. It would be nice to have switch-case statements support in > python. See the pattern-matching PEPs such as https://www.python.org/dev/peps/pep-0634/ In short, python soon will have a sort of switch statement, though the semantics will be a bit different and it is actually a form of pattern matching. See also the notes on pattern mathing in https://docs.python.org/3.10/whatsnew/3.10.html - DLD ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/FW76I53CMJTC2HXSIAO4DAJOSBKTCZ3U/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Add switch-case statements in Python
Sorry PEP 634 not PEP 643 ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/AGQLYE3D6X54A524ZRIPYTAMHSI5ZEXV/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Add switch-case statements in Python
Isn't PEP 643 for PEG grammar pattern matching? (I'm talking about switch statements in Python) ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/ZCGQYPC2JWKNRWNNEPHQVPG5FT4NGDJZ/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Add switch-case statements in Python
How is this differs from PEP 634 (https://docs.python.org/3.10/whatsnew/3.10.html#pep-634-structural-pattern-matching)? On 2021. 05. 04. 20:33, Shreyan Avigyan wrote: Most of programming languages out there have switch-case statements. Python doesn't have support for switch-case statements though. switch-case statements can sometimes be nice and tidy and sometimes it may be a horrible nightmare. But that also applies to if-elif-else statements. It would be nice to have switch-case statements support in python. Suggested syntax :- --- switch expr: case expr2: case expr3: statements default: statements How should it be implemented? --- First of all this will require a new syntax. Second I suggest for comparing the case expr with switch expr, compare the pointers instead of objects for better performance. Usually if the ladder is represented using if-elif-else logic then it would be lower performance because we'll end up comparing objects not pointers. ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/32SKTIZCNJP74ZJSHQ4R2R4A3ODC3LMN/ Code of Conduct: http://python.org/psf/codeofconduct/ ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/DPZM6JN2VR3PUWGGQEB2FLRU5YXJGH37/ Code of Conduct: http://python.org/psf/codeofconduct/