Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I would appreciate some insights / comments from Clojure regulars out there about my submission here.

(ns phrase)
(require '[clojure.string :as s])

(defn word-array
  [phrase]
  (-> (s/lower-case phrase)
      (s/split #"\W+")))

(defn word-count
  [phrase]
  (-> (word-array phrase)
      (frequencies)))
share|improve this question
    
It seems like a copy of the example code provided in the linked repository. What kind of feedback would you like about it ? –  omiel Feb 18 '14 at 18:32
    
Well I think it's a little bit shorter than the example. I just reworked my solution until I got the shortest form of it. I just wanted some comments on if this is like succinct clojure code and is it idiomatic. –  Low Kian Seong Feb 19 '14 at 1:00

1 Answer 1

I would format it like this:

(ns phrase
  (:require [clojure.string :as s]))

(defn word-array [phrase]
  (s/split (s/lower-case phrase) #"\W+"))

(defn word-count [phrase]
  (frequencies (word-array phrase)))

Notice that I included the require statement as part of the ns definition.

Whether or not you use threading macros (->, ->>) is generally a matter of personal preference, and there's nothing wrong with using them here, but I think in this case since you're only using 2 functions, I find the above easier to read. You might also consider using comp:

(def word-array (comp #(s/split % #"\W+") s/lower-case)
(def word-count (comp frequencies word-array))
share|improve this answer
    
Thank you very much for the suggestions. –  Low Kian Seong Mar 21 '14 at 2:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.