Iteration in herml
by Sean Cribbs
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:
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:
This proved to be much easier to parse and implement. We even have structured decomposition, like so:
And match ignores with
There’s still a lot to do, but it’s shaping up nicely. Check it out!