Ticket sales CLOSED!

Sunday 4:15 p.m.–4:35 p.m. in Terrace

Hy: A Lisp That Compiles to Python

James King

Audience level:


Hy is a Lisp that compiles to Python AST. It has full interoperability with Python and macros! This talk introduces Hy and will dig into the compiler and demonstrate how dynamically generating Python ASTs can be fun and useful.


Hy: A Lisp That Compiles to Python

Introducing Hy

  • 5 minutes

Hy was developed by @paultag and demonstrated to the world at a lightening talk at Pycon 2013. It is a lisp-like language that fully interoperates with Python. Lisp, if you don't already know, is a term for a family of computer languages and a former acronym that stood for Lots of Infuriating, Stupid Parenthesis. It's an incredibly useful language with lots of neat ideas that have been "borrowed" since it's inception by John McCarthy in 1956. What's cool about Hy is that it is still Python even if it does have lots of annoying parenthesis. And this is a good thing!

Getting Hy on Python

  • 10 minutes

The output of the Hy compiler is a Python AST. This is how Hy interoperates with Python. Hy can generate Python modules that can be called by Python code. Anything in Python is callable from Hy. We can step through Hy code with pdb. And the wonderful thing about dynamically generating Python ASTs is that Hy has real macros.

Basically every compiler is really a program made up a few smaller programs: a lexer, a parser, and a compiler. The first step in generating Python ASTs from Hy is to lex the source and generate a stream of tokens. The stream of tokens is read by the parser which interprets them into Hy's internal representations. This internal representation is then taken by the compiler and turned into a Python AST.

Macros are super-awesome. Because Hy code can be represented by the same data-structures as the data it operates on it becomes possible for us to write Hy programs that generate Hy programs using normal Hy code. This is normal. And it's really useful for writing succinct programs that are straight-to-the-point and bake-in their domain-knowledge. It also lets us programmatically generate Python programs.

Contributing is fun, easy, and welcome!

The Hy community is super-small right now but it is growing. You can find us on #hy on freenode and follow it on Github. We're a really friendly group and are very welcoming to people of all experience levels. It's a great way to learn about Python internals and a little Lisp on the side too.


  • 2 to 3 mins

Ask away!

Get in touch