-
Website
http://justin.harmonize.fm/ -
Original page
http://justin.harmonize.fm/index.php/2009/03/first-stab-at-learning-clojure/ -
Subscribe
All Comments -
Community
-
Top Commenters
-
maacl
1 comment · 2 points
-
davezor
1 comment · 1 points
-
aaronasjones
1 comment · 1 points
-
mebaran
1 comment · 1 points
-
miami web designer
1 comment · 1 points
-
-
Popular Threads
;-)
http://ociweb.com/jnb/jnbMar2009.html#Collections
I was under the impression that () was also a list. So you could do (1 ((2) 3)).
Also, it looks like "conj" can be applied to any sequence, but you're right about "assoc". There are others too that only work with vectors according to http://clojure.org/data_structures.
Vectors, on the other hand, don't treat the first item any differently. So [f x y] in Clojure is the same as [f, x, y] in Python.
Lisps like Clojure also have the notion of quoting, which languages like Python have no direct analogy to. By quoting an expression Clojure, we tell the compiler not to evaluate its contents. So (quote f x y) or '(f x y) will return a list of unevaluated symbols. We can evaluate them later on with eval, if we so desire, so (eval (quote f x y)) is equivalent to (f x y).
Oh, and you're right about conj - though in vectors conj appends to the end, whilst in lists it appends to the beginning.
(defservlet home
(GET "/"
(html [:h1 "Flockr"]
(html [:h2 "Twitter Portal"]))))
Doesn't take as long to get used to this style as it first appears, and it saves a heap of vertical space (like Python).
As far as readability, indentation should guide readers, not parens. If you try to tell what's going on by matching each paren one-by-one, you'll go crazy. If the code is properly indented, you won't have to; you let the indentation be your guide.
calculate(5
)
You wouldn't write that in other languages either.
However, I can see that it's not a popular decision. I hate relying on text editor features to write correct code, but if it's the way things are done...
Here's my fork of your gist: http://gist.github.com/76507
I totally agree with the bit about abstracting out html. I'm planning on re-factoring frequently as I go along, to kind of show an evolution from the simplest case to a well designed piece of software.
It's a bit easier to enforce this in other web frameworks that include the plumbing for these kind of abstractions in the first place, but I think I prefer this for learning the language. It abstracts away the details of dealing with HTTP requests and routing without getting in the way of the fun pieces. We'll see what comes out down the line as a result.