Pages

Thursday, July 21, 2022

Fedora 36 : first steps with the Hy.

Hy is a dialect of the Lisp programming language designed to interact with Python by translating s-expressions into Python's abstract syntax tree (AST). Hy was introduced at Python Conference (PyCon) 2013 by Paul Tagliamonte.
This is quite similar to the old GIMP Script Fu that I've worked with in the past. The syntax assumes a join like tabs in HTML, only we'll use parentheses. I haven't studied in detail the implications it has with the python language, but it certainly wasn't invented for nothing.
First, you need to install it with the pip tool.
[mythcat@fedora ~]$ pip3 install hy --user
Collecting hy
...
Successfully built hy
Installing collected packages: funcparserlib, colorama, hy
Successfully installed colorama-0.4.5 funcparserlib-1.0.0 hy-0.24.0
The I test some examples:
[mythcat@fedora ~]$ hy
Hy 0.24.0 using CPython(main) 3.10.5 on Linux
=> (setv a 1)
=> "hello world"
"hello world"
=> (setv mylist [1 2 3])

=> (get mylist 0)
1
=> (defn greet [name]
...  "Hello "
...  (print "Hello " name))
=> (greet "mythcat")
Hello  mythcat
You can test it online with this online tool: