Golo
— 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]
  Options:
        --help
       Prints this message
       Default: false
  Commands:
    version      Queries the Golo version
      Usage: version [options]
        Options:
              --full
             Prints the full information details
             Default: false

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

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

    golo      Dynamically loads and runs from Golo source files
      Usage: golo [options]
        Options:
              --args
             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)
println(a())
println(b())

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")
println(a)
println(b)
"""
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.

Templating

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>
<html>
  <head>
    <title>Golo Chat</title>
  </head>
  <body>
  <form action="/" method="post">
    <input type="text" name="msg">
    <input type="submit" value="Send">
  </form>
  <div>
    <h3>Last posts</h3>
    <% foreach post in posts { %>
      <div>
        <%= post %>
      </div>
    <% } %>
  </div>
  </body>
</html>
"""

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 – 2016 INSA-Lyon and contributors.

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