4 ms·
>What if we'd always had something like this in js? What if html would use round brackets and just use the closing bracket instead of the closing tag? e.g. <h
by toohotatopic 6y ago
>What if we'd always had something like this in js?
What if html would use round brackets and just use the closing bracket instead of the closing tag?
e.g. <html><body><div>foo</div></body></html>
could be:
(html (body (div 'foo')))
Something similar could be done for javascript. Instead of writing html in javascript we could write javascript in html.
Just imagine if we could represent the code as html or in that round bracket form:
function inc (x){
return x + 1;
}
could be:
<function name="inc" param="x"><add>x 1</add></function>
or with round brackets:
(function inc (x) (+ x 1))
- krebs_liebhaber 6y agoCongratulations - you've invented S-Expressions! Fortunately for you, there's a whole family of programming languages[0] that are based solely on this syntax! If you want to see a mature library that uses this syntax to represent both DOM elements and code, I'd suggest checking out Reagent[1]. [0] https://en.wikipedia.org/wiki/Lisp_(programming_language) https://en.wikipedia.org/wiki/Lisp_(programming_language) [1] https://reagent-project.github.io/ https://reagent-project.github.io/