DESCRIPTION.rst 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. MacroPy is an implementation of Macros in the Python Programming Language.
  2. MacroPy provides a mechanism for user-defined functions (macros) to perform
  3. transformations on the abstract syntax tree(AST) of Python code at module
  4. import time. This is an easy way to modify the semantics of a python program
  5. Python like you've never seen before
  6. ------------------------------------
  7. MacroPy allows you to create constructs which are impossible to have in normal
  8. python code, such as:
  9. Tracing
  10. ```````
  11. .. code:: python
  12. with trace:
  13. sum([x + 5 for x in range(3)])
  14. # sum([x + 5 for x in range(3)])
  15. # range(3) -> [0, 1, 2]
  16. # x + 5 -> 5
  17. # x + 5 -> 6
  18. # x + 5 -> 7
  19. # [x + 5 for x in range(3)] -> [5, 6, 7]
  20. # sum([x + 5 for x in range(3)]) -> 18
  21. Quick Lambdas
  22. `````````````
  23. .. code:: python
  24. print map(f[_[0]], ['omg', 'wtf', 'bbq'])
  25. # ['o', 'w', 'b']
  26. print reduce(f[_ + _], ['omg', 'wtf', 'bbq'])
  27. # 'omgwtfbbq
  28. Case Classes
  29. ````````````
  30. .. code:: python
  31. @case
  32. class Point(x, y): pass
  33. p = Point(1, 2)
  34. print str(p) #Point(1, 2)
  35. print p.x #1
  36. print p.y #2
  37. print Point(1, 2) == Point(1, 2) # True
  38. And more! All this runs perfectly on vanilla Python 2.7 or PyPy 2.0. For more
  39. details, see the `GitHub page <https://github.com/lihaoyi/macropy#macropy>`_.
  40. or ask in the `Google Group <https://groups.google.com/forum/#!forum/macropy>`_.