4 ms·
I've been thinking of this lately, with some cognitive dissonance. It's weird because I think of lisp s-expressions like a better version of json. Terraform, AW
by JimmyRuska 5y ago
I've been thinking of this lately, with some cognitive dissonance. It's weird because I think of lisp s-expressions like a better version of json. Terraform, AWS and others have tried to add loops and interpolation to json in weird ways that would have been natural for lisp syntax.
But lisp could be encoded into an html-like structure, and it has some nice benefit of more descriptive endings than parenthesis spaghetti, or potentially using what's inside the block as raw data that's easier to pass through than using a triple string quote.
eg define
<say-hello name:string=""> <print>say-hello:name say-hello:data</print> </say-hello>
invoke
<say-hello name="Joe">World</say-hello>
But I've always thought of json as an improvement to XML/HTML. There's been a lot of innovation and creative syntax like dhall and hcl, but some small modifications to HTML could make it more next-gen.
- ravi-delia 5y agoClojure 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.
- eyelidlessness 5y agoFWIW, 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)
- ravi-delia 5y agoMaybe 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.
- eyelidlessness 5y agoI 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.
- fulafel 5y agoFor 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/ https://hyperscript.org/docs/ which seems to also be a html/js system but not what is referred to here.
- DemocracyFTW 5y agoIOW similar to https://github.com/goodeggs/teacup https://github.com/goodeggs/teacup and a few other libraries that produce markup from inside a programming language with minimalized syntactic fuzz?
- ravi-delia 5y agoOh 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.
- tannhaeuser 5y agoLispers seemingly want to see everything as s-expr ;) In the case of SGML-heritage markup like HTML, often enough I've seen them fail to understand that it's not so much about arbitrarily nested element structures but about content models where an element contains a sub-element sequence specified by a regular expression (aka regular tree languages). This model information is then used to infer omitted tags, etc. It's also quite different from JSON.