Iteration in herml

herml is a Haml-like template language for Erlang that I’ve been developing with Kevin Smith. One of the major hurdles we’ve had to tackle is iteration, which is a pretty common idiom in template languages, but not so much in Erlang. In Erlang, one normally uses a tail-recursive function, lists:foreach(), or a list comprehension to iterate over a collection (list). Initially, Kevin had planned something like this:

[%tr
%td
@User || User <-@Users]

However, that proved to be too difficult to parse:

The opening bracket breaks with the style previously set forward.

The comprehension piece comes at the end, making it hard to know ahead of time what is being iterated over

Instead, on Thursday (erloungeRDU hack night), we agreed to do this simpler, but still LC-like syntax:

-[@User]<-@Users%td
@User

This proved to be much easier to parse and implement. We even have structured decomposition, like so: