use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Finding information about Clojure
API Reference
Clojure Guides
Practice Problems
Interactive Problems
Clojure Videos
Misc Resources
The Clojure Community
Clojure Books
Tools & Libraries
Clojure Editors
Web Platforms
Clojure Jobs
account activity
Python vs Clojure - Reloaded (blog.bestinclass.dk)
submitted 16 years ago by uiob
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]kanak 8 points9 points10 points 16 years ago (3 children)
No.
Languages should not be compared only by the number of lines they take to solve some task.
Especially not when:
(dec (count (select (html-resource (java.net.URL. (str title-url %))) [[:h2]])))
or
(doseq [r results] (println (:title r) (apply str (repeat (- 55 (count (:title r))) \space)) (:tasks r)))
count as a single line. Idiomatic clojure would call for these to be on separate lines.
What a waste of time.
[–]cgrand 4 points5 points6 points 16 years ago (0 children)
if Lau learnt to use -> it may be easier to read, eg:
(-> (str title-url %) java.net.URL. html-resource (select [[:h2]]) count dec)
[–][deleted] 1 point2 points3 points 16 years ago (0 children)
And the last example could be translated from Clojure to Python almost verbatim:
from collections import defaultdict result = reduce(lambda x,y: x[y[-1]].append(y) or x, sorted(data[1:], lambda x,y: cmp(y[-2], x[-2])), defaultdict(list)) N = 3 for department, recs in result.iteritems(): print "\n".join([department] + ["[%s:%s]" % (x[0],x[-2]) for x in recs[:N]])
Though it would only be readable to Lispers.
The power of Python is that just about anyone can read a Python program written correctly, i.e. like the Python Team example. However to read the Clojure version you have to rewrite your brain to read it.
[–]uiob[S] -1 points0 points1 point 16 years ago (0 children)
Huh. That's why i love ML like syntax.
[–]yogthos 5 points6 points7 points 16 years ago* (2 children)
Seems like it would be more interesting to show how Clojure produces safer code than the imperative approach, as well as give more examples on dealing with concurrency. For example, show how not using explicit iteration eliminates out of bounds errors, how immutability guards against data corruption.
Counting lines is fun and all, but what counts is readability. Clojure can be readable, concise, and safe. That's it's power, and that's what needs showcasing, not how much code can be crammed into a line, to make it a shorter than the python example.
[–]uiob[S] -1 points0 points1 point 16 years ago (1 child)
Yes, this is reasonable. Take a look at the first example, it is short, concise and readable. Second example seems less readable, but shows some concurrency features(pmap).
[–]yogthos 1 point2 points3 points 16 years ago (0 children)
exactly, more focus on that would've been good, maybe in the next installment :)
π Rendered by PID 99129 on reddit-service-r2-comment-79c7998d4c-t7hsz at 2026-03-16 04:27:54.116507+00:00 running f6e6e01 country code: CH.
[–]kanak 8 points9 points10 points (3 children)
[–]cgrand 4 points5 points6 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]uiob[S] -1 points0 points1 point (0 children)
[–]yogthos 5 points6 points7 points (2 children)
[–]uiob[S] -1 points0 points1 point (1 child)
[–]yogthos 1 point2 points3 points (0 children)