Macropy: Syntactic Macros for Python(macropy3.readthedocs.io)
macropy3.readthedocs.io
Macropy: Syntactic Macros for Python
https://macropy3.readthedocs.io/en/latest/
4 comments
Author here, funny to see this up here again after so many years. Happy to answer questions
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).
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
Other than `@case`, are there other examples of macropy macros?? @case means nothing to me.
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.
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.
The page has links to a dozen different examples, with code snippets and discussion of the motivations and potential use cases for each
Totally off topic, but I was wondering if you have looked at Coconut, a kind of ML Lite that compiles to Python? And if so, what do you think?
http://coconut-lang.org/
Are you still mainly programming in Scala? Do you see yourself programming in your current language in 5 years?
http://coconut-lang.org/
Are you still mainly programming in Scala? Do you see yourself programming in your current language in 5 years?
This project is great
Would love to see a new release on PyPI that works with Python > 3.4
;)
(last release seems to be "1.1b2" in 2018...)
Would love to see a new release on PyPI that works with Python > 3.4
;)
(last release seems to be "1.1b2" in 2018...)
Tail call optimization is appealing. Sometimes recursion is the cleanest implementation, but call depth is not known up front.
Very cool. Was this inspired by Hy?
Pretty sure we MacroPy predates Hy by about a year
Not unless there was an older repo that is now gone:
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.
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.
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.