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. ▲ 2
    MacroPy: Syntactic Macros for Python
    story by pmoriarty · 2017-10-12 · 0 comments
  13. …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
  14. …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
  15. 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
  16. …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
  17. …much more extensive things. 1. https://tomforb.es/automatically-inline-python-function-call... 2. https://github.com/lihaoyi/macropy
  18. https://github.com/lihaoyi/macropy
    comment by mycelium · 2015-09-08 · in Lisp is still a secret weapon
  19. …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
  20. …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
  21. ▲ 93
    Macros in Python: quasiquotes, case classes, LINQ and more
    story by mzl · 2015-05-26 · 18 comments
  22. …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
  23. 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?
  24. …repeated "defs", though. Here's another approach based on Macropy (basically, macros for Python): https://github.com/lihaoyi/macropy#pattern-matching .
  25. Oh yes, you can. But once you're doing that, why stop at a single statement? Why not macros https://github.com/lihaoyi/macropy
  26. ▲ 2
    Macros in Python: quasiquotes, case classes, LINQ and more
    story by luu · 2013-12-18 · 0 comments
  27. Indeed you can https://github.com/lihaoyi/macropy
  28. ▲ 3
    Macros in Python: quasiquotes, case classes, LINQ and more
    story by llambda · 2013-10-14 · 0 comments
  29. …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
  30. Most code don't need __setattr__ level of magic https://github.com/lihaoyi/macropy (search for "Levels of Magic")
  31. …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
  32. if you like to play with the AST, I think you could find useful https://github.com/lihaoyi/macropy
  33. > Can you add macros to python Yes https://github.com/lihaoyi/macropy
    comment by anonymous · 2013-06-25 · in Rarely Asked Questions
  34. ▲ 7
    MacroPy's Hygienic Macros in Python
    story by lihaoyi · 2013-06-08 · 4 comments
  35. ▲ 1
    MacroPy Parser Combinators, now with a complete JSON parser in 50 lines of code
    story by lihaoyi · 2013-06-03 · 0 comments
  36. ▲ 1
    A Fully-compliant JSON parser using MacroPy's Parser Combinators
    story by lihaoyi · 2013-06-03 · 0 comments
  37. ▲ 2
    JS Snippets: Cross compiling snippets of Python to Javascript
    story by lihaoyi · 2013-05-20 · 0 comments
  38. ▲ 1
    Writing your first Macro in Python
    story by lihaoyi · 2013-05-18 · 0 comments
  39. 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
  40. 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
  41. 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
  42. …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
  43. ▲ 300
    Macros in Python
    story by lihaoyi · 2013-05-13 · 66 comments
  44. ▲ 1
    LINQ to SQL, in Python
    story by lihaoyi · 2013-05-11 · 0 comments
  45. ▲ 8
    Macros in Python: quasiquotes, case classes, LINQ and more
    story by lihaoyi · 2013-05-08 · 2 comments
  46. ▲ 3
    Writing a JSON parser in Python
    story by lihaoyi · 2013-04-29 · 0 comments
  47. ▲ 1
    MacroPy Parser Combinators: Pushing the limits of embedded DSLs in Python
    story by lihaoyi · 2013-04-27 · 0 comments
  48. ▲ 11
    Show HN: MacroPy - bringing Macros to Python
    story by lihaoyi · 2013-04-23 · 2 comments