Hacker News new | ask | show | jobs
by candiodari 3415 days ago
Actually you can do function calls on Go templates [1], and indeed this is what is done in practice. Libraries got written to do this, and badly integrated [2].

You will quickly find if you use this that it's in fact worse: go templates have LISP syntax. A set of atoms, specified in reverse Polish notation, doing function application to all but the first atom.

[1] https://golang.org/pkg/text/template/#Template.Funcs

[2] https://github.com/Masterminds/sprig

1 comments

Yeah this is the reason I went ahead and wrote the template engine I mentioned in the parent comment. It compiles down to go templates. I inject generic math functions [1] and convert an expression like 4 + 5 * 3 to go template function calls. It's ugly but the compiler generates it so whatever :)

[1] https://github.com/eknkc/amber/blob/master/runtime.go