
Decoding Clojure - jacquesm
http://jacquesmattheij.com/decoding-clojure
======
icey
As far as I'm aware, there's not a true templating system around for
Compojure. There's Enlive, but that's kind of weird. From what I can see, you
write all your HTML and then perform operations on the HTML completely from
Clojure. If you were looking at the HTML you wouldn't know that it was going
to be modified by another program. It's one of the reasons that I haven't
spent more time working in Compojure - it assumes that everyone wants to spend
all their time in Clojure.

The problem (to me) is that s-exprs just make sense for representing HTML.
Every time I've tried to think of how a "perfect" templating language would
look for Clojure, all options have seemed silly next to just using Lisp. I
guess that's part of its charm (and its curse).

[Enlive: <http://github.com/cgrand/enlive>]

~~~
papaf
Clojure is powerful enough that its easy to write a "true" templating library
along the lines you describe. I wrote a very simple templating tool (47 loc)
that allowed clojure to be evaluated within PHP style tags -- I didn't use it
because I felt it doesn't add anything other than familiarity i.e. it was a
step backwards.

If you write your own html then compojure is, without question, the way to go.
S-expressions require less typing than html and you can write functions or
define snippets that build webpages up without the need to repeat yourself.
Its an end to copy and paste. Also, stylesheets are your friend and can do
most of the work of presentation.

If you work with designers who require full access to the HTML then Enlive is
a good option -- as you said there is no template code in with the html!
Surely this is a step forwards from custom comment fields or custom tags?

~~~
icey
Rolling your own templating library would certainly work, but then you're
stuck maintaining your own templating library.

I like the concept of Enlive, but I have concerns about troubleshooting it. I
feel like you're asking for trouble any time you have to look at multiple
files just to figure out what's going on in one page. Troubleshooting a page
that's been modified with Enlive would require you to have the HTML open, and
then mentally translate all the operations so that you can see what changes
what. I'm just not smart enough to be able to hold entire documents in my head
when things approach even moderate complexity, and I want to be able to scan a
document to see what's going on; not read the HTML document and then go
through the list of operations to see how that document is being modified.

------
mahmud
jacques, never put a lisp paren on a line by itself. K&R is for cc-mode
languages.

P.S. I see clojure uses // for a comment, a la C++; See if it accepts semi-
colons as well. That's quicker to type and easier on the eye.

~~~
pavelludiq
Clojure doesn't accept //, ; or (comment ) are used for comments.

------
RyanMcGreal
Can anyone recommend a good introductory book for learning Clojure?

~~~
icey
Mark Volkmann's Clojure page is a nice start:
<http://java.ociweb.com/mark/clojure/article.html>

(He has a bunch more content here: <http://java.ociweb.com/mark/clojure/> )

There is only one book out there currently, but it's pretty good:
_"Programming Clojure"_ by Stuart Sierra (there are 3 more coming, see below)

<http://pragprog.com/titles/shcloj/programming-clojure>

\--------------------------

Upcoming books:

○ Clojure in Action - <http://manning.com/rathore/>

○ The Joy of Clojure - <http://manning.com/fogus/>

○ Practical Clojure - <http://apress.com/book/view/1430272317>

~~~
sunkencity
I've read programming clojure and I found it very good. I also liked the
videos on <http://clojure.blip.tv/> and also I bought the peepcode screencast
with an intro on clojure. It's pretty good:
[http://peepcode.com/products/functional-programming-with-
clo...](http://peepcode.com/products/functional-programming-with-clojure)

This one is free and well worth the look:
[http://www.bestinclass.dk/index.php/2009/12/clojure-101-gett...](http://www.bestinclass.dk/index.php/2009/12/clojure-101-getting-
clojure-slime-installed/)

------
dkersten
A good editor with rainbow parentheses and parentheses matching makes lisp
code infinitely more readable.

~~~
jacquesm
Thanks, I'll be looking around for that.

It would save me a ton of time when looking at code I do not yet understand.

