Hacker News new | ask | show | jobs
by behnamoh 1378 days ago
It’s interesting that meta programming, one of the main selling points of lisps, is actually pretty common and possible in other languages as well. Lisp’s “code = data” achieves meta programming in a straightforward way, but this link shows that it’s not necessary. In fact, Python’s way might even be better because the language sorta “gets outta the way” because it’s really darn simple.
2 comments

The article however, does not show anything comparable to lispy metaprogramming.

I do not see a single new keyword being defined. I do not see anything changing the order of evaluation. Only to give 2 examples.

Recently I implemented a new kind of "define" in a Scheme, which allows for specifying contracts for a function. I don't think such a thing is possible using the tools shown in the article. As such, the things shown in the article are not really that meta, but rather parts of the Python language already. It is not like it is adding anything to Python, which was not there. It is just usage of some concepts Python already has. This is conceptually different from transforming source code to other source code, which then creates a new concept in the language itself. It is not like I can mold Python into whatever I want, but rather stay in the corset of the language facilities. Which of course is not as nice as lispy languages with good macro system, when it gets to creating DSLs and other conveniences.

So overall I am not so blown away by the article.

> Python’s way might even be better

Python recently got a form of structural pattern matching.

Can that be removed from Python, and then reimplemented only in Python? I mean other than by writing a .py file to .py file text filter?

Can it be backported to a prior version of Python?

Python's release history is full of "can't use this syntax if you're not on at least x.y.z version"; it continuously proves that it has it doesn't have metaprogramming on a level that could be used to develop the language. When the purveyors of Python decide to add some new syntax and semantics, they eschew Python metaprogramming and dive straight into C.