← Back to context

Comment by iLemming

2 months ago

> it just baffles me that Clojure decided to go a different way.

Have you scrolled to the end, or you're judging by the initial examples in the code, because author did use more sensible names in the refactored example.

But if I'd have to re-write your CL snippet in Clojure, perhaps it would look something like this (I don't know if that actually works, haven't tested it):

    (defn generate-random-sentence 
      ([mtab] (generate-random-sentence mtab (rand-nth (:first-words mtab))))
      ([mtab first-word]
       (->> (iterate #(pick-random-word (get (:prob-table mtab) %)) first-word)
            (take-while some?)
            (partition-by ends-with-end-sentence-punctuation?)
            (take 2)
            (apply concat)
            (clojure.string/join " "))))
             

I don't know why would anyone find it more (or less) readable. IMO Clojure version is a bit more functional, data-transformation oriented, while CL Loop gives you explicit control flow, there's memory efficiency, it's a single-pass processing, etc. At the end of the day, it all boils down to familiarity; you dislike Clojure maybe due to lack of exposure, yet it's not a bad Lisp, it really does shine in some areas and definitely it is a simpler Lisp than CL or even Elisp - the complexity of the loop macro alone is like learning another PL, yet for someone who knows it already it may feel easier to use.