Newbie question here. This code:
(println (flatten(map first '([1 2] [3 4] [5]
(def mapfirst (partial map first))
(println
(- '([1 2] [3 4] [5])
mapfirst
flatten
))
(println
(- '([1 2] [3 4] [5])
(partial map first)
flatten
))
prints out:
(1 3 5)
Got it. Thanks!
On Friday, June 7, 2013 3:29:55 PM UTC-6, Jonathan Fischer Friberg wrote:
On Fri, Jun 7, 2013 at 11:13 PM, Matt Smith matt.s...@gmail.comjavascript:
wrote:
(- '([1 2] [3 4] [5])
(partial map first)
flatten
)
Because this becomes
(flatten (partial '([1
I have been studying patterns or the notion of idiomatic code in
Clojure. The code in clojure.core has some good examples of proper
Clojure code and is well done. For that reason I was a bit surprised
at the definition for re-groups:
(defn re-groups [^java.util.regex.Matcher m]
(let [gc (.
On Aug 30, 10:16 am, Armando Blancas armando_blan...@yahoo.com
wrote:
It seems like the loop/recur is non-idiomatic for this usage and could
be done with either a map or reduce.
It could be that it's faster that way. How does you code perform?
Timings on this code for all three:
(time
Using the list comprehension (for) along with a helper function
(index)
(def y (list # #...O #.#.# I.#.# #...# #))
(defn index [s] (map #(vector %1 %2) s (range)))
(defn index-maze [maze-str]
(reduce conj {}
(for [r (index maze-str)
c (index (first r))]
(defn sleepsort [ s] (deref (reduce #(do (await (deref %2)) (deref
%2)) nil (doall (map #(future (Thread/sleep (* %1 100)) (send %2 conj
%1) %2) s (repeat (agent [])))
user=(sleepsort 2 1 6 5)
[1 2 5 6]
By having the future return the agent, the reduce then calls deref on
all the futures
problem: convert a collection [1 2 0 1 2 3 0 1 2 3 0 0 1 2] into
partitions like:
((1 2) (0 1 2 3) (0 1 2 3) (0) (0 1 2))
In this case, start each partition on a 0.
I looked at the various partition functions but none of them would do
the trick without adding unnecessary complexity. Instead I