News for hackers. Stuff that matters.
Re:Writing HTML with Racket and X-Expressions (2019) by TylerE on Wednesday April 01, 2020 @12:37AM (#22745733)
The 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.

Re:Writing HTML with Racket and X-Expressions (2019) by fulafel on Wednesday April 01, 2020 @01:13AM (#22745909)
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) by slifin on Wednesday April 01, 2020 @05:04AM (#22746926)
This is probably one of the major things that Clojure gets right (ignoring EAVT databases) that no one copies

You don't need a CSS preprocessor if you can manipulate your CSS using the standard data manipulators in your given language, this applies to so many DSL languages like HTML, CSS, SQL, Clojure has Hiccup, Gardern and HoneySQL respectively

Here's a PHP SQL port I've been working on https://github.com/slifin/moonlight (keywords removed for ergonomics but it did lose power when I did that)

If a third party gives you a stringy language to work with you gain power back by creating a data representation, operating on that then converting it back to string at the execution point

In the case of PHP we took the Java route and put everything into objects: https://github.com/zendframework/zend-db, the amount of code required to do that is almost comical when compared, Zend DB also suffers from a lot of bugs/lack of features compared to honeySQL which is about 5 files of data orientated code: https://github.com/jkk/honeysql

I should mention Zend DB is not an outlier here for bulky code have a look at other PHP query builders they're all impenetrable

Re:Writing HTML with Racket and X-Expressions (2019) by TylerE on Wednesday April 01, 2020 @01:16AM (#22745915)
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) by fnordsensei on Wednesday April 01, 2020 @03:10AM (#22746431)
The `:` is not visual noise, it indicates that it is a keyword. Without it, you're indicating that you're writing a symbol. Symbols are evaluated, so keywords is a better choice given that they always are what they say they are, whereas you could define `div` to mean `<p>`, point to a function, or any number of other things.

You could write a macro to use symbol names literally, so that `div` always means `<div>`, but then you'd have a macro where none was needed, and you'd have no obvious way of using symbols in a non-literal/evaluated way.

Fulcro[1] lies little closer to what you're after. The above would be:

  (div 
    (p "I am a component!")
    (p :.someclass
       "I have " (strong "bold")
       (span {:style {:color "red"}} "and red") "text."))
This is since Fulcro defines the element tags as functions, which are called in order, rather than as a data structure that's interpreted (a la Hiccup).

The immediate and obvious benefit of Hiccup over the function hierarchy is that Hiccup can be trivially (and safely) seralized/deserialized.

1: https://github.com/fulcrologic/fulcro

Re:Writing HTML with Racket and X-Expressions (2019) by fulafel on Wednesday April 01, 2020 @01:18AM (#22745927)
The advantage is that you can include normal Clojure expressions in it without any special syntax. Also lets you compose Hiccup data and forms without having two mental models of the data representation. Worthy tradeoffs IMO.
Re:Writing HTML with Racket and X-Expressions (2019) by mjn on Wednesday April 01, 2020 @01:19AM (#22745931)
In Common Lisp land, there's spinneret, which does something like that: https://github.com/ruricolist/spinneret

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) by ilotro on Wednesday April 01, 2020 @07:42AM (#22747689)
https://koyoweb.org/haml/index.html uses macros to add haml-inspired features on top of xexprs.
Re:Writing HTML with Racket and X-Expressions (2019) by state_less on Wednesday April 01, 2020 @05:04AM (#22746927)
You can avoid parens and have some fun building up HTML with combinators.

  > numbers n = docTypeHtml $ do
  >     H.head $ do
  >         H.title "Natural numbers"
  >     body $ do
  >         p "A list of natural numbers:"
  >         ul $ forM_ [1 .. n] (li . toHtml)
https://jaspervdj.be/blaze/tutorial.html
Re:Writing HTML with Racket and X-Expressions (2019) by athenot on Wednesday April 01, 2020 @12:43AM (#22745768)
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.)

Re:Writing HTML with Racket and X-Expressions (2019) by TylerE on Wednesday April 01, 2020 @12:55AM (#22745841)
That's not bad!

HTML is one case where I think significant whitespace is a really obvious win.