Some things that stand out from your code:
(def next-appendage #())
is really(defn next-appendage [part done])
- Do not use anonymous functions except for really really short functions. You next-appendage function is long for Clojure standards.
- Instead of
hash-map
you can use the map literal directly `{:name (clojure.string/replace ,,,} - Even though it seems cool when you are starting Clojure, one liners are very hard to read. You already know that is "really ugly" :)
- It is unusual to use
loop
. Most of the time you can replace it with a simplermap
or similar - 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:
(def next-appendage #())
is really(defn next-appendage [part done])
- Do not use anonymous functions except for really really short functions. You next-appendage function is long for Clojure standards.
- Instead of
hash-map
you can use the map literal directly `{:name (clojure.string/replace ,,,} - Even though it seems cool when you are starting Clojure, one liners are very hard to read. You already know that is "really ugly" :)
- It is unusual to use
loop
. Most of the time you can replace it with a simplermap
or similar - 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:
(def next-appendage #())
is really(defn next-appendage [part done])
- Do not use anonymous functions except for really really short functions. You next-appendage function is long for Clojure standards.
- Instead of
hash-map
you can use the map literal directly `{:name (clojure.string/replace ,,,} - Even though it seems cool when you are starting Clojure, one liners are very hard to read. You already know that is "really ugly" :)
- It is unusual to use
loop
. Most of the time you can replace it with a simplermap
or similar - 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:
(def next-appendage #())
is really(defn next-appendage [part done])
- Do not use anonymous functions except for really really short functions. You next-appendage function is long for Clojure standards.
- Instead of
hash-map
you can use the map literal directly `{:name (clojure.string/replace ,,,} - 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" :)
- It is unusual to use
loop
. Most of the time you can replace it with a simplermap
or similar - 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:
(def next-appendage #())
is really(defn next-appendage [part done])
- Do not use anonymous functions except for really really short functions. You next-appendage function is long for Clojure standards.
- Instead of
hash-map
you can use the map literal directly `{:name (clojure.string/replace ,,,} - Even it seems cool when you start with Clojure, one liners are very hard to read. You already know that is "really ugly" :)
- It is unusual to use
loop
. Most of the time you can replace it with a simplermap
or similar - 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:
(def next-appendage #())
is really(defn next-appendage [part done])
- Do not use anonymous functions except for really really short functions. You next-appendage function is long for Clojure standards.
- Instead of
hash-map
you can use the map literal directly `{:name (clojure.string/replace ,,,} - Even though it seems cool when you are starting Clojure, one liners are very hard to read. You already know that is "really ugly" :)
- It is unusual to use
loop
. Most of the time you can replace it with a simplermap
or similar - 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:
(def next-appendage #())
is really(defn next-appendage [part done])
- Do not use anonymous functions except for really really short functions. You next-appendage function is long for Clojure standards.
- Instead of
hash-map
you can use the map literal directly `{:name (clojure.string/replace ,,,} - Even it seems cool when you start with Clojure, one liners are very hard to read. You already know that is "really ugly" :)
- It is unusual to use
loop
. Most of the time you can replace it with a simplermap
or similar - 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)))))