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.
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:
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.
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:
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!
Recent Comments