Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Some things that stand out from your code:

  1. (def next-appendage #()) is really (defn next-appendage [part done])
  2. Do not use anonymous functions except for really really short functions. You next-appendage function is long for Clojure standards.
  3. Instead of hash-map you can use the map literal directly `{:name (clojure.string/replace ,,,}
  4. Even though it seems cool when you are starting Clojure, one liners are very hard to read. You already know that is "really ugly" :)
  5. It is unusual to use loop. Most of the time you can replace it with a simpler map or similar
  6. Do not use read-string Do not use read-string, unless you know what you are doing

My version would look like:

(defn add-apendages [times part]
 (let [ ;; find the prefix and initial number
 [_ prefix number-str] (first (re-seq #"(.*)-([0-9]+)$" (:name part)))
 ;; parse the number, using Java interop
 initial-number (Integer/parseInt number-str)]
 ;; Build the list of results using a simple map operation
 (map (fn [n] {:name (str prefix "-" n)})
 (range initial-number (+ 1 initial-number times)))))

Some things that stand out from your code:

  1. (def next-appendage #()) is really (defn next-appendage [part done])
  2. Do not use anonymous functions except for really really short functions. You next-appendage function is long for Clojure standards.
  3. Instead of hash-map you can use the map literal directly `{:name (clojure.string/replace ,,,}
  4. Even though it seems cool when you are starting Clojure, one liners are very hard to read. You already know that is "really ugly" :)
  5. It is unusual to use loop. Most of the time you can replace it with a simpler map or similar
  6. Do not use read-string, unless you know what you are doing

My version would look like:

(defn add-apendages [times part]
 (let [ ;; find the prefix and initial number
 [_ prefix number-str] (first (re-seq #"(.*)-([0-9]+)$" (:name part)))
 ;; parse the number, using Java interop
 initial-number (Integer/parseInt number-str)]
 ;; Build the list of results using a simple map operation
 (map (fn [n] {:name (str prefix "-" n)})
 (range initial-number (+ 1 initial-number times)))))

Some things that stand out from your code:

  1. (def next-appendage #()) is really (defn next-appendage [part done])
  2. Do not use anonymous functions except for really really short functions. You next-appendage function is long for Clojure standards.
  3. Instead of hash-map you can use the map literal directly `{:name (clojure.string/replace ,,,}
  4. Even though it seems cool when you are starting Clojure, one liners are very hard to read. You already know that is "really ugly" :)
  5. It is unusual to use loop. Most of the time you can replace it with a simpler map or similar
  6. Do not use read-string, unless you know what you are doing

My version would look like:

(defn add-apendages [times part]
 (let [ ;; find the prefix and initial number
 [_ prefix number-str] (first (re-seq #"(.*)-([0-9]+)$" (:name part)))
 ;; parse the number, using Java interop
 initial-number (Integer/parseInt number-str)]
 ;; Build the list of results using a simple map operation
 (map (fn [n] {:name (str prefix "-" n)})
 (range initial-number (+ 1 initial-number times)))))

Some things that stand out from your code:

  1. (def next-appendage #()) is really (defn next-appendage [part done])
  2. Do not use anonymous functions except for really really short functions. You next-appendage function is long for Clojure standards.
  3. Instead of hash-map you can use the map literal directly `{:name (clojure.string/replace ,,,}
  4. Even though it seems cool when you start withare starting Clojure, one liners are very hard to read. You already know that is "really ugly" :)
  5. It is unusual to use loop. Most of the time you can replace it with a simpler map or similar
  6. Do not use read-string, unless you know what you are doing

My version would look like:

(defn add-apendages [times part]
 (let [ ;; find the prefix and initial number
 [_ prefix number-str] (first (re-seq #"(.*)-([0-9]+)$" (:name part)))
 ;; parse the number, using Java interop
 initial-number (Integer/parseInt number-str)]
 ;; Build the list of results using a simple map operation
 (map (fn [n] {:name (str prefix "-" n)})
 (range initial-number (+ 1 initial-number times)))))

Some things that stand out from your code:

  1. (def next-appendage #()) is really (defn next-appendage [part done])
  2. Do not use anonymous functions except for really really short functions. You next-appendage function is long for Clojure standards.
  3. Instead of hash-map you can use the map literal directly `{:name (clojure.string/replace ,,,}
  4. Even it seems cool when you start with Clojure, one liners are very hard to read. You already know that is "really ugly" :)
  5. It is unusual to use loop. Most of the time you can replace it with a simpler map or similar
  6. Do not use read-string, unless you know what you are doing

My version would look like:

(defn add-apendages [times part]
 (let [ ;; find the prefix and initial number
 [_ prefix number-str] (first (re-seq #"(.*)-([0-9]+)$" (:name part)))
 ;; parse the number, using Java interop
 initial-number (Integer/parseInt number-str)]
 ;; Build the list of results using a simple map operation
 (map (fn [n] {:name (str prefix "-" n)})
 (range initial-number (+ 1 initial-number times)))))

Some things that stand out from your code:

  1. (def next-appendage #()) is really (defn next-appendage [part done])
  2. Do not use anonymous functions except for really really short functions. You next-appendage function is long for Clojure standards.
  3. Instead of hash-map you can use the map literal directly `{:name (clojure.string/replace ,,,}
  4. Even though it seems cool when you are starting Clojure, one liners are very hard to read. You already know that is "really ugly" :)
  5. It is unusual to use loop. Most of the time you can replace it with a simpler map or similar
  6. Do not use read-string, unless you know what you are doing

My version would look like:

(defn add-apendages [times part]
 (let [ ;; find the prefix and initial number
 [_ prefix number-str] (first (re-seq #"(.*)-([0-9]+)$" (:name part)))
 ;; parse the number, using Java interop
 initial-number (Integer/parseInt number-str)]
 ;; Build the list of results using a simple map operation
 (map (fn [n] {:name (str prefix "-" n)})
 (range initial-number (+ 1 initial-number times)))))
Source Link

Some things that stand out from your code:

  1. (def next-appendage #()) is really (defn next-appendage [part done])
  2. Do not use anonymous functions except for really really short functions. You next-appendage function is long for Clojure standards.
  3. Instead of hash-map you can use the map literal directly `{:name (clojure.string/replace ,,,}
  4. Even it seems cool when you start with Clojure, one liners are very hard to read. You already know that is "really ugly" :)
  5. It is unusual to use loop. Most of the time you can replace it with a simpler map or similar
  6. Do not use read-string, unless you know what you are doing

My version would look like:

(defn add-apendages [times part]
 (let [ ;; find the prefix and initial number
 [_ prefix number-str] (first (re-seq #"(.*)-([0-9]+)$" (:name part)))
 ;; parse the number, using Java interop
 initial-number (Integer/parseInt number-str)]
 ;; Build the list of results using a simple map operation
 (map (fn [n] {:name (str prefix "-" n)})
 (range initial-number (+ 1 initial-number times)))))
lang-clj

AltStyle によって変換されたページ (->オリジナル) /