MacroPy 0.1.2: Macros for Pythoon. Quasiquotes, Case Classes, Pattern Matching, LINQ and more!
Haoyi Li
haoyi.sg at gmail.com
Wed May 8 23:32:48 CEST 2013
Hey All,
MacroPy is an implementation of Macros in the Python Programming, providing a mechanism for user-defined functions (macros) to perform transformations on the abstract syntax tree(AST) of Python code at module import time. This is an easy way to modify the semantics of a python program in ways which are otherwise impossible, for example providing an extremely concise way of declaring classes:
@case
class Point(x, y)
p = Point(1, 2)
print p.x # 1
print p # Point(1, 2)
Apart from this, we've used MacroPy's macros to implement a pretty impressive list of features:
- Quasiquotes
- String Interpolation
- Pyxl, integrating XML markup into a Python program
- Tracing and Smart Asserts
- Case Classes, easy Algebraic Data Types from Scala
- Pattern Matching from the Functional Programming world
- LINQ to SQL from C#
- Quick Lambdas from Scala and Groovy,
- Parser Combinators, inspired by Scala's.
The full documentation is over on github (https://github.com/lihaoyi/macropy) if anyone wants to check it out. It runs fine on both CPython 2.7 and PyPy 1.9, and I've just pushed the last up-to-date version of MacroPy to PyPI:
https://pypi.python.org/pypi/MacroPy
Hope someone finds this useful!
Thanks!
-Haoyi
More information about the Python-announce-list
mailing list