5 ms·
Wow, definitely something I am going to check out. From a quick look, it seems that your Lisp code for the example looks a lot like HTML itself. For example:
by parennoob 14y ago
Wow, definitely something I am going to check out. From a quick look, it seems that your Lisp code for the example looks a lot like HTML itself. For example:
(defun blogpage (&optional (posts *posts*))
(html-frame
"Restas Blogdemo"
(<:div
(<:a :href (genurl 'add) "Add a blog post")
(<:hr)
(render-posts posts))))
I don't know much about functional programming though, so sorry if that's an incorrect assumption.
- pavelludiq 14y agoFunctions starting with <: are generated by the sexml library for outputting xml and html from lisp expressions. There are many similar libraries in pretty much every lisp dialect.
- aerique 14y agoSee cl-who for another example: http://weitz.de/cl-who/#syntax http://weitz.de/cl-who/#syntax Also, this has nothing to do with functional programming but rather with creating a DSL (http://en.wikipedia.org/wiki/Domain-specific_language http://en.wikipedia.org/wiki/Domain-specific_language) More links: • http://www.tfeb.org/lisp/hax.html#HTOUT http://www.tfeb.org/lisp/hax.html#HTOUT • https://github.com/franzinc/aserve/blob/master/htmlgen/test.cl https://github.com/franzinc/aserve/blob/master/htmlgen/test....
- parennoob 14y agoAh, thanks. That was very helpful, specially the second link.
- gcr 14y agoMost of the Lisp web frameworks look like that, taking advantage of Lisp's flexible syntax. Here's a Racket example. If you download http://racket-lang.org http://racket-lang.org, you can just run this (no extra libraries or anything) and a browser window will pop up for you. #lang web-server/insta ;; A "hello world" web server (define (start request) (response/xexpr '(html (body (h1 "Hello, world!") (a ([href "http://google.com"]) "Google") (br) "I hope you like my site!")))) This example renders as: <html><body><h1>Hello, world!</h1><a href="http://google.com>Google</a><br http://google.com>Google</a><br />I hope you like my site!</body></html> See also: http://docs.racket-lang.org/continue/ http://docs.racket-lang.org/continue/
- shn 14y agoI need help understanding one thing. This code generates HTML code. Fine. But how come code and declaration (web designer and developer) are separated with this. Is this a good practice? I've been reading about lisp for a long time, not in depth, but I keep stumbling similar snippets a lot. Are there any good examples out there? I am teaching myself Clojure (reading the book with the bird cover) these days.
- jwr 14y agoThey are not separated. This approach appeals to geeks/programmers, but is completely impractical, as I've learned the hard way in several projects. In a practical setting you will get a set of pre-cut HTML/CSS and images. Good luck splitting that into semantic markup and styling. And good luck teaching a designer how to work with it afterwards. Because of hard-earned experience I try very hard not to put any HTML into my code, keeping it all in templates, which are much more accessible to designers and easier to modify.
- muraiki 14y agoYes, this is exactly why I stayed away from things like this, despite my love for Racket and Clojure, until someone above pointed out the Enlive library. It lets you use normal HTML files as your templates but requires no code in it (not even for loops!) Basically, you use CSS-style selectors to replace the contents of elements, giving you the full power of Clojure but without having to either put code in your templates or put HTML into your code. https://github.com/swannodette/enlive-tutorial/ https://github.com/swannodette/enlive-tutorial/
- pavelludiq 14y agoI have decided to investigate the possibility to include a sub-chapter to chapter 3 to discuss Caramel for people who like enlive(me included). I didn't already do so because caramel is brand new, and I haven't had the time to try it out beyond a few simple examples. The choice to use s-expressions was made because It makes it easier to just type code in a repl and experiment, without having to worry about dealing with templates, and also because I wanted the first example to fit in a single file.