Writing HTML with Racket and X-Expressions (2019)
1–10 of 30 posts
Re: Writing HTML with Racket and X-Expressions (2019)
#2If you're going to do it, do it right... use macros.
Of course, then you'd end up something that looks a lot like Haml (http://haml.info/) with parens everywhere.
Re: Writing HTML with Racket and X-Expressions (2019)
#3The idea is right, but all the 'quoting and explicit list calls make this super awkward. If you're going to do it, do it right... use macros. Of course, then you'd end up something that looks a lot like Haml ( http://haml.info/ ) with parens everywhere.
https://pugjs.org/language/mixins.html
(I think there's a python port too, but I use the JS version both in Node and in the browser.)
Re: Writing HTML with Racket and X-Expressions (2019)
#4The idea is right, but all the 'quoting and explicit list calls make this super awkward. If you're going to do it, do it right... use macros. Of course, then you'd end up something that looks a lot like Haml ( http://haml.info/ ) with parens everywhere.
In an even more minimalistic syntax, there is Pug. Similar example as the article: https://pugjs.org/language/mixins.html (I think there's a python port too, but I use the JS version both in Node and in the browser.)
HTML is one case where I think significant whitespace is a really obvious win.
Re: Writing HTML with Racket and X-Expressions (2019)
#5The idea is right, but all the 'quoting and explicit list calls make this super awkward. If you're going to do it, do it right... use macros. Of course, then you'd end up something that looks a lot like Haml ( http://haml.info/ ) with parens everywhere.
(defn simple-component []
[:div
[:p "I am a component!"]
[:p.someclass
"I have " [:strong "bold"]
[:span {:style {:color "red"}} " and red "] "text."]])Re: Writing HTML with Racket and X-Expressions (2019)
#6The idea is right, but all the 'quoting and explicit list calls make this super awkward. If you're going to do it, do it right... use macros. Of course, then you'd end up something that looks a lot like Haml ( http://haml.info/ ) with parens everywhere.
The Hiccup notation in the Clojure world (eg Reagent) works well, and it doesn't need macros. You're still left with some quoting (for text inside elements and attributes), but in practice most of these come from non-constant values in code. (defn simple-component [] [:div [:p "I am a component!"] [:p.someclass "I have " [:strong "bold"] [:span {:style {:color "red"}} " and red "] "text."]])
Re: Writing HTML with Racket and X-Expressions (2019)
#7Earlier quoted context omitted.
The Hiccup notation in the Clojure world (eg Reagent) works well, and it doesn't need macros. You're still left with some quoting (for text inside elements and attributes), but in practice most of these come from non-constant values in code. (defn simple-component [] [:div [:p "I am a component!"] [:p.someclass "I have " [:strong "bold"] [:span {:style {:color "red"}} " and red "] "text."]])
Not a fan. Given that in a template context the first atom will always be a symbol, all the : is just redundant. I despise visual noise.
Re: Writing HTML with Racket and X-Expressions (2019)
#8The idea is right, but all the 'quoting and explicit list calls make this super awkward. If you're going to do it, do it right... use macros. Of course, then you'd end up something that looks a lot like Haml ( http://haml.info/ ) with parens everywhere.
I use it to generate my academic publications list, although I'm not 100% satisfied with the elegance of the resulting code: https://github.com/anadrome/cl-pubgen/blob/master/generate-p...
Re: Writing HTML with Racket and X-Expressions (2019)
#9> We've lost a lot of expressiveness: what if we wanted to create a nested list again? We could make it a template macro, but we have to do extra work to call it inside itself, and suddently we have an extra language to learn.
Not that I’ve used jinja aside from some Ansible, I don’t get the second language part for templates or why templates are limiting? Even React’s syntax really isn’t that different from a template as you need to enclose JS expressions in curly braces right?
My favorite HTML server language is Elixir which has a Ruby flavored template engine called using ``. It’s only 4 “tags” [1]. Well maybe since it’s a functional language and everything is an expression the semantics are simpler, mainly limited to whether or not to return a value. Jinja probably is more difficult since Python control flow isn't an expression so you add another layer (probably same in Ruby, Java, etc). Calling functions is as easy as ensuring they’re in the scope of where it’s loaded (or just the current scope when using the ~E sigil. So in the first example encapsulating a sub-lists is just creating a function that returns a template. When compiled it’ll create functions that return IO lists so it’s pretty efficient too [2].
Given that, I prefer having HTML look like HTML.
1: https://hexdocs.pm/eex/EEx.html 2: https://edmz.org/personal/2016/09/06/phoenix_templates-_yup,...