5 ms·
A Lisp gives you all of this and more in a single, consistent, powerful programming language. I fail to see why we need three vastly different, intricate and co
by wz1000 11y ago
A Lisp gives you all of this and more in a single, consistent, powerful programming language. I fail to see why we need three vastly different, intricate and complex technologies when we could have done with just one simple, elegant language. Languages like Scheme are mind bogglingly small, yet amazingly powerful.
For example, in ClojureScript:
<img id=animal src="my_kitten.jpg">
becomes
(html [:image {:id "animal" :src "my_kitten.jpg"}])
All in one nice, consistent programming language. Code is data and data is code.
(html [:ol
(for [x (range 1 4)]
[:li x])])
XML/HTML is just a watered down Lisp with less parenthesis and more superfluous syntax and text.
- founderling 11y agoThumbs up for actually giving an example! Personally, I prefer the HTML version over the ClojureScipt version. It is shorter and to me it is much more readable.
- deleted 11y ago[deleted]
- wz1000 11y ago> Personally, I prefer the HTML version over the ClojureScipt version. It is shorter and to me it is much more readable. That is only because this is Lisp that generates HTML. Also, in the example you had given, there are no closing tags. Closing tags are just superfluous visual clutter and are not actually needed. To take an example from http://c2.com/cgi/wiki?LispVsXml http://c2.com/cgi/wiki?LispVsXml This XML <dictionary> <email>electronic mail</email> <html>hypertext transport language</html> <xml>extensible markup language</xml> </dictionary> can become (dictionary (e-mail "electronic mail") (html "hypertext transport language") (xml "extensible markup language")) As you can see, all the superfluousness of the XML syntax is lost and reduced to its bare minimum.
- founderling 11y agoThat is only because this is Lisp that generates HTML. Ok, so it is not the way you initially stated '<img id=animal src="my_kitten.jpg"> becomes (html [:image {:id "animal" :src "my_kitten.jpg"}])'. You rather showed an example of how to create html elements programmatically. Then you should compare it to JS: Your ClojureScript: (html [:image {:id "animal" :src "my_kitten.jpg"}]) My JS: html("image",{id:"animal",src:"my_kitten.jpg"}) If we use a function html(elementType,properties) that creates an element. Looks pretty nice to me.
- wz1000 11y agoYes, my second example which translated XML to equivalent Lisp would be better at illustrating my point. With a Lisp, you don't need HTML as there is no distinction between code and data. Your Lisp is rendered and displayed on screen. It doesn't emit an intermediary language. How do you programmatically manipulate this "data"? Within Lisp itself. Lisp acts as both HTML and JavaScript. Lisp programmers regularly do this with the power of Lisp macros. I suggest you read the "Lisp vs XML" page I linked to in order to understand this better. Lisp directly exposes its syntax tree to the programmer and allows them to manipulate it to their liking.
- founderling 11y agoLisp acts as both HTML and JavaScript So do you propose to make the separation of content and behaviour go away? Because that is one of the key features of the HTML+CSS+JS structure. I like the content/presentation/behavior separation from a developers point of view and from a users point of view. As a developer, I love to know what I am currently working on. In HTML, I define the structure of the content. In CSS, I define how it looks. In JS I define the behaviour. Lovely. As a user, much of the time I browse the web without JavaScript. Because I am only interested in the content. Not in popups that beg me to join newsletters, animated things that make the page more "fun" or ads that try to grab my attention. Also I often disable the pages stylesheet so I get a nicely readable big font with good contrast to the background.
- saiko-chriskun 11y ago<img id=animal src="my_kitten.jpg"> :: 35 chars [:image {:id "animal" :src "my_kitten.jpg"}] :: 44 chars To me they look practically identical.
- reagency 11y agoAnd with a few trivial bits of syntactic sugar, they get even closer.
- lewisl9029 11y ago> much more readable. I think this is more of a side-effect of familiarity rather than any inherent differences in readability between the two forms. Lisps do tend to look foreign to most people because their first languages usually have C-like syntax, and Lisp vs C is a much more dramatic difference than say Python vs C. Being able to write code that also happens to be valid data structures has some very tangible benefits though. For instance, in the HTML example, you can replace the strings or keywords in it with variables and it will be evaluated and output into the final HTML. You can also take that HTML element, pass it into any number of map, filter, reduce functions and programmatically transform it in literally any way you want. This means when you write HTML this way, you can use ClojureScript as your template language, and I think it's safe to say that ClojureScript is a much more powerful and well-designed language than any template language out there designed for HTML.