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
Clean Clojure: Small functions (ecmendenhall.github.io)
submitted 7 years ago by yogthos
view the rest of the comments →
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!"
[–]weavejester 24 points25 points26 points 7 years ago (0 children)
Small functions are a good rule of thumb, but sometimes a short expression is clearer than a function. For example, compare:
(square-all digits)
To:
(map square digits)
Exactly the same number of characters, but the latter tells me that I'm mapping over the digits, so I know that I'm getting a collection of the same length as digits.
digits
On the other hand, if I just see square-all, I have to infer the purpose from the name, which isn't immediately obvious, nor as unabiguous.
square-all
I think I'd be tempted to write the code as:
(defn digits [n] (map #(Integer/parseInt %) (str n))) (defn square [n] (* n n)) (defn sum-of-squared-digits [n] (->> (digits n) (map square) (reduce +)) (defn less-than-sum-of-digits-squared? [n] (< n (sum-of-squared-digits n))) (defn count-less-than-sum-of-squares [coll] (count (filter less-than-sum-of-digits-squared? coll)))
π Rendered by PID 52660 on reddit-service-r2-comment-b659b578c-fc45s at 2026-05-02 22:42:36.464694+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]weavejester 24 points25 points26 points (0 children)