The Hy Programming Language – Part 2

Written by on March 9, 2024 in Hy Language, Programming with 0 Comments

I wrote about “Hy” language in an earlier article. Since then I have been exploring the language some more, trying to get a better understanding of its features. 

The following example uses inheritance to model different types of “Space” objects such as Asteroid, SpaceShip and Planet. It is taken from an earlier article that explained how “Multimethods” in Lisp can be used to model dynamic dispatch of method calls.

Inheritance Example

Inheritance Example

In the above code, I first define classes to model the different “space objects”. Some of these classes define a “collide” method and print a string describing which space object collides with what other space object. Finally, I create instances of these classes and invoke the “collide” method. Here is the output:

Output

Output

As expected, in the case of Asteroid and Mars, their overriding “collide” method is used, but for others the default method defined in “SpaceObject” is invoked. 

For the next example, I decided to use the popular “langchain” framework to interact with an “LLM”. Here is the code.

Langchain Example

Langchain Example

The code demonstrates a very basic interaction mode of “langchain”, and uses an open-source LLM from “HuggingFaceHub”. Make sure you get the required API token.

Here is the output from the program:

LLM Output

LLM Output

Based on the limited time that I have spent with “Hy” language, I find it is very usable and easy to adopt if you already know Python. 

Have a nice weekend!

Tags: , , ,

Subscribe

If you enjoyed this article, subscribe now to receive more just like it.

Subscribe via RSS Feed

Leave a Reply

Your email address will not be published. Required fields are marked *

Top