— a lightweight dynamic language for the JVM.

back to the front page

 Golo news roundup #6

Philippe at the Montpellier JUG

(Philippe at the Montpellier JUG, instagram courtesy of Christophe Hamerling)

This new edition of the Golo news roundup is fruitful!

Small changes

A brand new command-line interface

Golo used to have golo, goloc and gologolo commands. We unified those in a simpler golo command that is built with JCommander:

Usage: golo [options] [command] [command options]
       Prints this message
       Default: false
    version      Queries the Golo version
      Usage: version [options]
             Prints the full information details
             Default: false

    compile      Compiles Golo source files
      Usage: compile [options] Golo source files (*.golo)
             The compiled classes output directory
             Default: .

    run      Runs compiled Golo code
      Usage: run [options] Program arguments
        *     --module
             The Golo module with a main function

    golo      Dynamically loads and runs from Golo source files
      Usage: golo [options]
             Program arguments
             Default: []
        *     --files
             Golo source files (the last one has a main function)
             Default: []

A significant advantage is that the interface is more uniform, and the usage of commands will make it easier to evolve.

Dynamic code evaluation

We added a gololang.EvaluationEnvironment class for the dynamic evaluation of Golo code.

You can use it in many ways, such as for loading an anonymous module:

let env = gololang.EvaluationEnvironment()
let code =
function a = -> "a!"
function b = -> "b!"
let mod = env: anonymousModule(code)
let a = fun("a", mod)
let b = fun("b", mod)

You can load a function in different ways, such as in:

let env = gololang.EvaluationEnvironment()
let code = "|a, b| -> (a + b) * 2"
let f = env: def(code)
println(f(10, 20))

And finally you can just run a piece of one-shot code:

let env = gololang.EvaluationEnvironment()
let code = """println(">>> run_map")
let values = java.util.TreeMap(): add("a", 1): add("b", 2)
env: run(code, values)

There are more options to dynamic code evaluation than presented here, so you are invited to have a look at the documentation.


We added a lightweight template engine in Golo. Because a picture is worth a thousand words, here is a self-describing example:

let template = """
<%@params posts %>
<!DOCTYPE html>
    <title>Golo Chat</title>
  <form action="/" method="post">
    <input type="text" name="msg">
    <input type="submit" value="Send">
    <h3>Last posts</h3>
    <% foreach post in posts { %>
        <%= post %>
    <% } %>

let tpl = gololang.TemplateEngine(): compile(template)
println(tpl(someDataModel: posts()))

The compilation of a template gives a (compiled) Golo function to render templates.

This is a great way to embed Golo into your applications for templating purposes. Please note that the implementation remains simple: it does not check for template and generated code correctness. That being said, one can inspect compilation exceptions: they carry a list of reported problems as well as the generated Golo code for a template.

On the Eclipse front

Jeff Maury is still making progress with the Golo Language Develoment Tools (GLDT) for Eclipse.

You can get it by pointing your Eclipse update center to http://gldt-update-site.golo-lang.org/nightly

Do not forget to help Jeff and give him feedback: https://github.com/golo-lang/gldt.

That’s all, folks!

As you can guess with so many changes, we are close to a new preview release. Stay tuned!

Thanks again for your interest in Golo!

– Julien

comments powered by Disqus

Copyright © 2012 – 2018 INSA Lyon, CITI Laboratory and contributors.

Privacy Policy | Terms of Use | Copyright Agent | Eclipse Public License | Legal Resources