What is Golo? Golo is a lightweight dynamic language for the JVM. Yes, again! But a simple one!
Golo is build with invokedynamic. Golo is easy to use and even easy to modify (it will be the subject of a future article).
It was invented by Julien Ponge (the well known @jponge) the @TypeUnsafe Boss, but also a talented researcher at Dynamid.
Golo is a proof of Dynamid invokedynamic expertise and a powerfull tool to work with dynamic middlewares. To my mind, Golo is is also a great way to prototype your idea quickly using all the possibilities of the Java ecosystem. Indeed, Golo is born to “play” with Java. Golo simplify Java and help you to create nice DSL. You can think to Golo as syntactic sugar for Java.
Today, we’ll take a quick tour of Golo to learn basis.
Golo is so simple that you can learn it only reading source code samples ;)
Functions and closures/lambda
Create a main.golo file :
Run it : golo golo --files main.golo
Use and Augment Java
Create a jar file from this source java code :
# Use Toon class with Golo
Run it : golo golo --classpath jars/*.jar --files main.golo
(my jar file is in the jars directory)
Remarks: please note the : notation for calling instance method and .notation for calling the class method.
# Add abilities to Toon class with Golo
With the augment keyword you can add method to Java types (custom types as Toon but even core Java types as String, LinkedList, …) :
No Class with Golo, but we have some very powerful elements of languages
# The structure
And you can augment structures too!:
# The DynamicObject
DynamicObject is a very flexible structure of Golo language which advantageously replaces the classes, with a touch of functional programming (no troll!) :
# # DynamicObject and mixin
There is no inheritance, but you can mixin DynamicObjects:
# # Chaining pattern with DynamicObjects
It’s very usefull to create some DSL:
Golo plays with Java (again) with the dynamic adapters
Remember our Toon class, you can create an adapter of acme.Toon and re implement the hello() method: