Hacker GitHub

← All repos

lihaoyi/macropy

View on GitHub ↗ ★ 3,308 TSQL

Macros in Python: quasiquotes, case classes, LINQ and more!

48 mentions on Hacker News by 26 people: 15 stories, 33 comments · first 2013-04-23 · latest 2025-11-29

Mentions per year 48 mentions · busiest year 2013 (23)
20082026
  1. I actually implemented something of this sorts back in college: MacroPy https://github.com/lihaoyi/macropy
    comment by lihaoyi · 2025-11-29 · in PEP 638 – Syntactic Macros
  2. You can make macros in Python: https://github.com/lihaoyi/macropy (note that that project was started for a class taught by Sussman) There's also a PEP to make them first-class: https://peps.python.org/pep-0638/
  3. …Hissp. https://www.gnu.org/software/m4/ https://threeofwands.com/algebraic-data-types-in-python/ https://github.com/lihaoyi/macropy https://github.com/gilch/hissp
  4. Maybe MacroPy? https://github.com/lihaoyi/macropy
    comment by uyt · 2021-02-25 · in Python for Lisp Programmers (2000)
  5. …of metaprogramming are already there, it just takes some libraries to put them on your fingertips https://github.com/lihaoyi/macropy The "LISP is homoiconic" trope is oversimplified; the Python stdlib gives access to the compiler, parse…
  6. 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…
    comment by tekacs · 2020-05-16 · in Macropy: Syntactic Macros for Python
  7. https://github.com/lihaoyi/macropy
  8. …mutation one can inflict upon the runtime is magnificent! http://farmdev.com/src/secrets/framehack/ https://github.com/lihaoyi/macropy
    comment by sitkack · 2019-08-15 · in Rust 1.37.0
  9. Another one? https://github.com/lihaoyi/macropy
  10. …to parse conventional languages down to an AST tree, work on the tree, and run that code. See https://github.com/lihaoyi/macropy Sometimes I wonder if the LISP cult is just trying to pretend Noam Chomsky was never born.
  11. …while using them is pretty cool, I don't think the implementation of the macros is very nice. [1] https://github.com/lihaoyi/macropy
    comment by icebraining · 2018-02-15 · in Homoiconicity isn’t the point (2012)
  12. …don't need to write a parser, btw, because the stdlib provides one for you (in `ast` module). [1] https://github.com/lihaoyi/macropy
    comment by klibertp · 2017-06-29 · in Fantastic DSLs and where to find them
  13. …https://github.com/lampepfl/dotty/issues/2491 and https://github.com/lihaoyi/Scalite and (say) https://github.com/lihaoyi/macropy . [1]: Properties in Python also have the underlying design of using descriptors, which are a whole other…
    comment by tekacs · 2017-05-27 · in Warts of Scala
  14. I think you would be very pleased with and interested in macropy. https://github.com/lihaoyi/macropy
    comment by canjobear · 2016-09-10 · in Changing Python lambda syntax at runtime
  15. …for "case" classes that produce objects with a similar behavior to "attr.s" generated objects https://github.com/lihaoyi/macropy
    comment by d0mine · 2016-08-26 · in Using attrs for everything in Python
  16. …much more extensive things. 1. https://tomforb.es/automatically-inline-python-function-call... 2. https://github.com/lihaoyi/macropy
  17. https://github.com/lihaoyi/macropy
    comment by mycelium · 2015-09-08 · in Lisp is still a secret weapon
  18. …that it's not the most impressive example of what you can do with macros (see my other post). [0]: https://github.com/lihaoyi/macropy#skeletons-in-the-closet
  19. …3.4 support is not quite ready [0], and attempting to install it with `pip3` just fails. [0]: https://github.com/lihaoyi/macropy/issues/32
  20. …I am not sure anyone has ever seriously used this ability. It certainly isn't main stream. Checkout https://github.com/lihaoyi/macropy for inspiration. Norvig agrees with this assessment: http://norvig.com/python-lisp.html . Given that…
    comment by timtadh · 2014-11-10 · in Half a decade with Go
  21. Sweet.js ( http://sweetjs.org ) and MacroPy ( https://github.com/lihaoyi/macropy ) come to mind. Actually "real macros" are just macros which operate on AST instead of on strings, they are hard to do if you have to re-implement language…
    comment by klibertp · 2014-08-15 · in Why don't I metaprogram more?
  22. …repeated "defs", though. Here's another approach based on Macropy (basically, macros for Python): https://github.com/lihaoyi/macropy#pattern-matching .
  23. Oh yes, you can. But once you're doing that, why stop at a single statement? Why not macros https://github.com/lihaoyi/macropy
  24. Indeed you can https://github.com/lihaoyi/macropy
  25. …algebraic data types and to perform pattern matching. This is the closest thing i found for that: https://github.com/lihaoyi/macropy
    comment by neur0mancer · 2013-10-13 · in Functional Python Made Easy
  26. Most code don't need __setattr__ level of magic https://github.com/lihaoyi/macropy (search for "Levels of Magic")
  27. …this point since most of the features are there. [1] http://docs.python.org/3/library/ast.html [2] https://github.com/lihaoyi/macropy
    comment by StefanKarpinski · 2013-08-14 · in Metaprogramming – Julia Language
  28. if you like to play with the AST, I think you could find useful https://github.com/lihaoyi/macropy
  29. > Can you add macros to python Yes https://github.com/lihaoyi/macropy
    comment by anonymous · 2013-06-25 · in Rarely Asked Questions
  30. Author here, I just put up a Detailed Guide: https://github.com/lihaoyi/macropy#detailed-guide That goes into more detail of how macros are written, and walks you through writing a simple but useful macro (the quicklambda macro). This…
    comment by lihaoyi · 2013-05-13 · in Macros in Python
  31. Yep, there's an issue for that! https://github.com/lihaoyi/macropy/issues/14 I've also gotten a basic implementation working in the CPython REPL, which requires you to run a function `macro_repl()` before you can use them. A Macro powered…
    comment by lihaoyi · 2013-05-13 · in Macros in Python
  32. It's actually pretty simple and almost all in this file: https://github.com/lihaoyi/macropy/blob/master/macropy/core/... Those already familiar with the imp mechanism and AST module could probably infer it from the description. An…
    comment by tekacs · 2013-05-13 · in Macros in Python
  33. …give a TL;DR on the whole library, but case classes can be used with for example pattern matching ( https://github.com/lihaoyi/macropy#pattern-matching ). The following code: with patterns: Foo(x, Bar(3, z)) << Foo(4, Bar(3, 8)) The…
    comment by asm89 · 2013-05-13 · in Macros in Python