Re:Macropy: Syntactic Macros for Python
by kbob on Sunday May 17, 2020 @09:44PM
(#23217321)
Macropy transforms Python's AST. So it doesn't allow anything that Python can't parse.
I spent some time earlier this year looking at tapping into the Python compilation process before the AST is generated, in order to allow statements that are not legal Python syntax.
It's definitely possible using the `tokenize` module, but doing it right was turning into more work than the quick hack I wanted.
Re:Macropy: Syntactic Macros for Python
by cjauvin on Saturday May 16, 2020 @10:56AM
(#23203874)
I don't know much about macros and it revived my interest for this topic, thanks. I wonder if it could be used to embed SQL statements directly in Python code? (not sure it would be a good idea, but it would make for an interesting experiment maybe).
Re:Macropy: Syntactic Macros for Python
by lihaoyi on Saturday May 16, 2020 @10:57AM
(#23203891)
As implemented, we do not change the superficial python syntax. That has a number of advantages around compatibility, but it means embedding raw SQL outside string literals isn’t possible. We could do things like validating/transforming SQL strings at compile time, like what we do with string interpolators or pyxl strings
Re:Macropy: Syntactic Macros for Python
by dhash on Saturday May 16, 2020 @10:51AM
(#23203830)
Lihaoyi mostly authors scala libraries. I switched from python to scala and found many of the things that I love about scala ported to python with this library.
Case classes (pretty .toString, structural equality, .copy, and destructuring), Scala 3-esque enums, f-string interpolations before python added them, pattern matching, and _ based lambdas are the highlights for me.
I spent some time earlier this year looking at tapping into the Python compilation process before the AST is generated, in order to allow statements that are not legal Python syntax.
It's definitely possible using the `tokenize` module, but doing it right was turning into more work than the quick hack I wanted.
Case classes (pretty .toString, structural equality, .copy, and destructuring), Scala 3-esque enums, f-string interpolations before python added them, pattern matching, and _ based lambdas are the highlights for me.
http://coconut-lang.org/
Are you still mainly programming in Scala? Do you see yourself programming in your current language in 5 years?
Would love to see a new release on PyPI that works with Python > 3.4
;)
(last release seems to be "1.1b2" in 2018...)
https://github.com/lihaoyi/macropy/graphs/contributors
https://github.com/hylang/hy/graphs/contributors
It looks like macropy started around 6 months after Hy, around a time when Hy had multiple contributors going.
Perhaps Hy hadn’t really been heard about yet.