Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Python Enhancement Proposal 638 – Syntactic Macros (python.org)
5 points by pansa2 on Sept 26, 2020 | hide | past | favorite | 3 comments


Sigh. Soon Python will no longer be cool. It will be the excel of programming languages and something else will come along.

There is a spot where the language is right enough. And adding more features/syntax is just making it worse. Maybe worse is not the right word... making it too complex.


All the facilities to do that kind of metaprogramming are already there, it just takes some libraries to put them on your fingertips

https://github.com/lihaoyi/macropy

The "LISP is homoiconic" trope is oversimplified; the Python stdlib gives access to the compiler, parse trees, bytecode, etc. There are more moving parts, but with the edges sanded off syntactic macros should be comfortable in Python -- and take the burden of innovation off CPython and PyPy promoting simplicity there for the long term.

The Python folks have been switching Python to a PEG grammar

https://www.python.org/dev/peps/pep-0617/

At the moment I am little disappointed at the Py 3.10 source code because they haven't exposed the PEG parser to Python programmers yet as they promised. You could use this to do little stunts like adding an "unless x:" statement equivalent to "if not x:" or write a parser for the strange query language your organization uses that lets you sort the dict's it returns to you in the same order you put the fields in the select clause...


> You could use this to do little stunts like adding an "unless x:" statement equivalent to "if not x:"

You say that like it's a good thing. Python is a language empowered by its constraints. You have indeed always been able to pull stunts like this but it's strongly frowned upon - python is not ruby, lambdas intentionally do not have statements, and terseness is not a virtue.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: