3 ms·
Hy is a self-compiling macro. Macros are just programmable mini-compilers embedded in the host language. This lets you do neat things like take a declarative de
by agentultra 12y ago
Hy is a self-compiling macro. Macros are just programmable mini-compilers embedded in the host language. This lets you do neat things like take a declarative description of a process and compile it into an executable function:
https://github.com/paultag/snitch/blob/master/example.hy https://github.com/paultag/snitch/blob/master/example.hy
I gave a talk at Pycon last year that discussed, among other things, the implementation of a constraint solver for games. You can implement an answer-set language on top of it in order to make it easier to use for yourself or collaborators in pure-Python... but writing AST-transforming code using Python's `ast` module is a huge pain. Just sprinkle some parens around and you can treat the Python AST as if it were just another plain-old-datastructure. It becomes magnitudes easier to write your answer-set solver's language interface.
And because Hy is freely importable from Python code you can simply use it to write that front-end compiler for your constraint solver. The rest of your code can be in Python if that works better for you.
But it doesn't stop there... you also get Hy's core library. Which provides some nice higher order functions and macros which compile down to really nice, idiomatic Python code. The kind of code you'd want to write to express that idea.
It's a nice tool to have.
(as a contributor I'm slightly biased).