Hacker News new | past | comments | ask | show | jobs | submit login

Clojure has basically this in Hiccup, far and away the best HTML templating experience I have ever had. You don't mix in code with HTML, you just write your code exactly as you normally would. It's a fantastic coding experience, and really really made me wish for something similar in Elixir.



FWIW, after spending some time exploring JSX implementations I think JSX is actually more spiritually aligned which lisp/s-expressions than Hiccup is. JSX commonly has a mental model that maps to hyperscript (which is a good baseline model), and that aligns with Hiccup perfectly. But JSX isn’t hyperscript, it’s a DSL that doesn’t define any runtime semantics. It’s also commonly associated with React or similar VDOMs, but nothing specifies that it actually evaluates to that. The only thing that’s specified is that it’s an expression and has specific expression syntax.

An increasingly popular example of how far that can be taken is Solid/DOM Expressions, which eliminate JSX at compile time and produce reactive DOM calls. It’s easy (at least since I’ve been exploring the space) to imagine compiling the same JSX to absolutely different implementations.

Granted Hiccup lives in a language with first class macros so it’s easy to imagine the same there too! But Hiccup itself is essentially hyperscript, and would need to be executed in a macro designed for that to be as versatile as JSX.

(Here’s hoping there’s interest in that! Every time I dive in this space I find myself wishing it all existed in a lisp and not in a Wild West of AST tooling)


Maybe I'm just an idiot here (haven't really used JSX outside of React) but what would you consider spiritual alignment to s-expressions? There's a lot of baggage that comes along with them, and Hiccup carries some but not all, but at the end of the day Hiccup is actually composed of literal s-expressions.


I hoped I explained the position clearly in the first place, but I’ll try again. Ultimately Hiccup is hyperscript in Clojure syntax. It’s literally s-expressions, yes, and insofar as that’s true so is JSX compiled to h or equivalent. But JSX’s compilation target is undefined until specified by the developer, and like a lisp DSL it can be and often is compiled from its list structure into semantically very different computations. Again, all possible with Hiccup, but at least from what I saw when I worked in Clojure that wasn’t typically the case, it was almost always a very direct 1:1 mapping to hyperscript. Which is fine, it’s a good model for rendering UI! I just think it’s fascinating that I see more application of the advantages of lisp (macros, DSLs, creative/clever optimization of using and computing essentially a list of symbols) in the JSX space.


For others following along at home who haven't heard of hyperscript before, you can track down leads by searching for react-hypescript - otherwise you'll endup at https://hyperscript.org/docs/ which seems to also be a html/js system but not what is referred to here.


IOW similar to https://github.com/goodeggs/teacup and a few other libraries that produce markup from inside a programming language with minimalized syntactic fuzz?


Oh that looks neat! I mentioned Hiccup because the person I replied to specifically called out lispy languages, but yeah I saw that there were similar options for other languages.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: