Hylang 1.0.0
Published:
The Hy programming language saw its first stable release yesterday. While not introducing any new semantics, Hy is a great improvement on Python's sometimes atrocious syntax and it fixes the expression-statement dichotomy. I like how Hy's rolling—it's a much more stylish language than Python in my opinion.
Pros
Hy brings regularity, order, and sanity into the world of Python.
(print "Hello, World!")
Sure, the above does not really strike awe into the cold, dead hearts of programmers. However, consider the following:
(print (+
(len (with [o (open "foo")] (.read o)))
(len (with [o (open "bar")] (.read o)))))
Now we are cooking! Since everything is an expression we don't have to create temporary variables to return values computed by statements.
Let's see if Hy managed to fix one of Python's bigger pieces of brain damage - scoping of variables:
(when True
(setv x 42)
(print x)) ; When ends here, so x should be erased.
(print x) ; This SHOULD be an error.
The second print works, meaning the scoping is still broken. Probably to avoid surprising Python programmers too much. However...
(let [satan 666]
(print satan)) ; Works as expected, satan is printed.
(print satan) ; How about this, though?
The second print is an error! Yes!
Hy also lets you use kebab-case in names:
(print (setx döner-mit-scharf "danke schön"))
döner-mit-scharf
; => "danke schön"
It's so simple and I like it very much! (Both the kebab-case and actual kebab.)
Cons
There are things I don't like in Hy. For example, the syntax for updating lists:
(setv li ["a" "b" "c"])
(setv (get li 0) "x")
li
; => ["x" "b" "c"]
The verbosity is somewhat annoying, but it is a price I am prepared to pay for all the other improvements.
Sure, I would rather get dot as the access operator with special handling to actually allow it to be used infix, but I will not be complaining. It would have been beautiful:
(setv li [ 1 2 3 ])
(setv di { "a" 1 "b" 2 })
li.0
; => 1
di.a
; => 1
You can get an approximation of this by using metadict, as shown on Hy's homepage:
(import metadict [MetaDict])
(setv d (MetaDict))
(setv d.foo 1) ; ie, (setv (get d "foo") 1)
d.foo ; ie, (get d "foo")
; => 1
(list (.keys d))
; => ["foo"]
Still, I think it would be nice to get this in the core language.
Python is dead! Long live Hy!
What does this all mean? Is the future bright? Well... not really.
I probably will not be using Hy to replace official Python at work. I imagine people would revolt seeing Lisp syntax in a patch, especially if the patch was being pushed into a Python repository. "Insignificant whitespace?! Not on my watch!"
For personal projects? Hell yeah! You can be sure I will kick Python's official syntax right off of my property and invite Hy to take its place.
Next: Chciałbym być taki jak ja - Krzysztof Sokołowski
Previous: Programming and Alchemy