Imperative thinking vs Language expressiveness vs. Versatility

one-more-for-the-road

Its always nice to complete a challenge in 4clojure.com, especially when you feel you’ve articulated the solution in the most readable form. I’ve just completed the pairwise-disjoint problem, which is pure set algebra: Given a set of sets, find out if these sets have any elements in common. Enough with talk, here’s the code in all its recursive beauty:

(fn pairwise-disjoint [set-of-sets]
 (or
  (empty? set-of-sets) 
  (let [examined-set   (first set-of-sets)
        remaining-sets (rest set-of-sets)
        disjoint-map   (map #(clojure.set/intersection examined-set %) remaining-sets)
        disjoint       (every? empty? disjoint-map)]
   (and disjoint (pairwise-disjoint remaining-sets))
)))

The nice thing about 4Clojure is that it reveals other users’ answers so I just found out you can do the same in one single line, so the solution can be as terse as:

one-more-for-the-road-2

Woa there! I understand that the «imperative» way of thinking prevails throughout my solution, but is this one single line readable? Yes it achieves the same goal, but does the poor soul that’ll read this single line in 20 years from now understand its purpose?

Σχολιάστε

Εισάγετε τα παρακάτω στοιχεία ή επιλέξτε ένα εικονίδιο για να συνδεθείτε:

Λογότυπο WordPress.com

Σχολιάζετε χρησιμοποιώντας τον λογαριασμό WordPress.com. Αποσύνδεση /  Αλλαγή )

Φωτογραφία Google

Σχολιάζετε χρησιμοποιώντας τον λογαριασμό Google. Αποσύνδεση /  Αλλαγή )

Φωτογραφία Twitter

Σχολιάζετε χρησιμοποιώντας τον λογαριασμό Twitter. Αποσύνδεση /  Αλλαγή )

Φωτογραφία Facebook

Σχολιάζετε χρησιμοποιώντας τον λογαριασμό Facebook. Αποσύνδεση /  Αλλαγή )

Σύνδεση με %s