3 ms·
As a user of Clojure and an onlooker of things like mustache (and handlebars) who has used neither of the latter, this post left me incredibly confused. I like
by bascule 15y ago
As a user of Clojure and an onlooker of things like mustache (and handlebars) who has used neither of the latter, this post left me incredibly confused. I like the points about destructuring and having something like a let binding. Those seem like useful addition.
However, about half the post discusses how "looping and conditional branching are conflated", and the end focuses on adding a separate branching construct to what's supposed to be a logic-free templating language. So I guess what he's trying to say is he wants to add logic to a logic-free templating language. It seems like he missed the point of Mustache: Looping and branching are conflated by design to eliminate logic from the template.
About the only way I see the connection between Clojure and Mustache at all is through the potential value destructuring could bring, and destructuring isn't exactly a feature which is unique to Clojure (CoffeeScript, Scala, and Erlang come to mind). Otherwise this post is apples and oranges: Clojure macros are about as far as you can get from a logic-free templating language. I'm wondering if the additions he proposes are sufficient to turn what's supposed to be a logic-free templating language into a Turing-complete one (see this example of why XSLT is Turing-complete: http://www.unidex.com/turing/utm.htm http://www.unidex.com/turing/utm.htm)
- stevelosh 15y agoLooping and branching are conflated by design to eliminate logic from the template. That doesn't eliminate logic, it just makes it annoying and obtuse. You can still branch in mustache templates, and you can still loop. No particular kind of logic has been eliminated. But now you need to know what a particular item happens to be in order to know what the magic branch/loop operator is going to do. About the only thing it prevents is saying "show this if X is truthy", but only prevents it when X is a list! Removing the ability to do something for some arbitrary objects doesn't make the language clean and logic-free, it makes it annoying and complicated.
- bascule 15y agoExcept there's no logic in the language itself, from the perspective of Mustache what you're doing is purely declarative. Adding an explicit "if" operator does introduce logic into the language, and may very well make the language sufficiently expressive to be Turing complete.
- true_religion 15y agoIt wouldn't make it turning complete because while the template could read the hypothetical infinite tape, and write infinitely to another tape---it can't write what its written so its prohibited from being turing complete. It's basically a finite state machine. Now you can do a whole lot with a FSM---and lo, some people will claim that our current brand of machines are only realistically as powerful as FSMs because of the lack of infinite memory.
- bascule 15y agoThe proposed changes, particularly tail recursion, an if operator, and a zip operator in effect give you a functional language with immutable state. While you can't "write" to the Turing tape as a side effect as the language is immutable, you can create a new "tape" from previous states which is a modified version of the old tape.
- riffraff 15y agoI don't understand the idea that mustache is logicless. Why is something that shows a message "only if person has a truthy value": {{#person}} Hi {{name}}! {{/person}} different from an `if` (except it becomes a `for` depending on the value of the argument)? As long as you use values consistently it is never the case that a single person object referred by a variable "person" transforms into a set of people.
- chrisvest 15y agoI'm sorry the article left you confused. It did end up a bit on the long side and is probably not as well edited as it could have been. You do not eliminate, or even reduce, the amount of logic at work by conflating looping and branching because now, apart from the normal function of these constructs, the language (or its runtime) is also making decisions about which one of these to use when given a particular piece of data. The truth is that Mustache isn't logic-free, because it has looping and branching, and it can even call methods and functions with its lambda feature. The only template language I know of that is actually logic-free is Rife Templates: http://rifers.org/wiki/display/RIFE/GuideTemplates.html http://rifers.org/wiki/display/RIFE/GuideTemplates.html What you discover when you use that system, is that templates without logic can't really do much, so you have to control them with logic that sits outside of the templates. As for destructering, I considered adding a Haskell example, but that idea didn't really work with where I was going with the story on data. In the end I am the most familiar with Clojures destructuring, plus its data story was a really good match here, so I just stuck with it.