The Hy mascot, a happy-looking cartoon cuttlefish

Hy

Hy is a Lisp dialect that's embedded in Python.

Hy (or "Hylang" for long) is a multi-paradigm general-purpose programming language in the Lisp family. It's implemented as a kind of alternative syntax for Python. Compared to Python, Hy offers a variety of new features, generalizations, and syntactic simplifications, as would be expected of a Lisp. Compared to other Lisps, Hy provides direct access to Python's built-ins and third-party Python libraries, while allowing you to freely mix imperative, functional, and object-oriented styles of programming. (More on "Why Hy?")

To install the latest release of Hy, just use the command pip3 install --user hy. Then you can start an interactive read-eval-print loop (REPL) with the command hy, or run a Hy program with hy myprogram.hy.

Example code

See the tutorial for many more examples.

HyPython
(setv foobar (+ 2 2)) (setv [tim eric] ["jim" "derrick"]) (setv alpha "a" beta "b") foobar = 2 + 2 tim, eric = 'jim', 'derrick' alpha = 'a'; beta = 'b'
(sorted "abcBC" :key (fn [x] (.lower x))) sorted("abcBC", key = lambda x: x.lower())
(defn test [a b [c "x"] #* d] [a b c d]) def test(a, b, c="x", *d): return [a, b, c, d]
(with [o (open "file.txt" "rt")] (setv buffer []) (while (< (len buffer) 10) (.append buffer (next o)))) with open('file.txt', 'rt') as o: buffer = [] while len(buffer) < 10: buffer.append(next(o))
(lfor x (range 3) y (range 3) :if (= (+ x y) 3) (* x y)) [x * y for x in range(3) for y in range(3) if x + y == 3]
(defmacro do-while [test #* body] `(do ~@body (while ~test ~@body))) (setv x 0) (do-while x (print "Printed once.")) x = 0 print("Printed once.") while x: print("Printed once.")