This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # admin-announcements (130)
- # alternate-reality (2)
- # aws (20)
- # beginners (49)
- # boot (1)
- # braid-chat (18)
- # cljsrn (54)
- # clojars (1)
- # clojure (70)
- # clojure-art (1)
- # clojure-japan (21)
- # clojure-miami (2)
- # clojure-my (7)
- # clojure-russia (60)
- # clojurescript (75)
- # community-development (12)
- # core-matrix (7)
- # cursive (23)
- # datomic (31)
- # dirac (2)
- # dunaj (3)
- # dysphemism (5)
- # editors-rus (1)
- # emacs (22)
- # events (9)
- # funcool (56)
- # hoplon (63)
- # human (1)
- # jobs (9)
- # ldnclj (7)
- # lein-figwheel (21)
- # leiningen (1)
- # off-topic (2)
- # om (61)
- # onyx (20)
- # other-lisps (2)
- # portland-or (1)
- # proton (26)
- # re-frame (27)
- # reagent (16)
- # ring-swagger (30)
- # spacemacs (6)
- # yada (5)
Hello, I am doing iloveponies course on clojure. So far I am enjoying it. I am stuck with an exericse, and unable to understand the soultion @akiva, maybe you can help
(reduce #(str %1 " " %2) a-seq) , can somebody explain how would this work?. What does # signify and how does %1 %2 get assigned values
Thanks @kamn , I see, but in the above code, how does reduce get invoked with 2 params?
np. It still gets me because for whatever reason when I see reduce I think map first then I realize there is a remainder
@ratnakar: @kamn: What worked for me in groking
reduce was to think it calls a fn over each element of a seq where the first arg in fn is the accumulating value and the second arg is the current value from the seq.
Use reduce when you want to consume a sequence and produce a single value (or combine a number of values in some way to produce a smaller sequence). Whenever you think of using recursion (or a
for) to consume a sequence and produce a value consider
Hi, can you help me debugging a OutOfMemoryError Java heap space? I'm trying to move data from Mongodb to Postgres using Monger and clojure.java.jdbc. After some millions rows I'm running out of heap space... The relevant part of the code is
from what I know everything except for my
(defn translate-list [mongo-rows] (map translate mongo-rows)) (defn insert-list! [db-spec table coll] (apply (partial j/insert! db-spec table) coll)) (defn go  (let [mongo-rows (mc/find-maps mongo "events") batches (partition-all 100000 mongo-rows)] (map #(insert-list! db :events (translate-list %)) batches)))
translatefunction should be lazy. If I decrease the partition size I'm able to load more rows but eventually I get the exception
I guess that the return value of the
map call is realized and thus you’ll end up with all the values in memory.
(doseq [b batches] (insert-list! db :events (translate-list b)) should do it.
@ordnungswidrig: is it because
Does not retain the head of the sequence. ?
@mbarbieri: the other reason to use
doseq rather than
map is that you are mapping a function over a sequence only for a side effect (i.e. a db insert). See this from @stuartsierra http://stuartsierra.com/2015/08/25/clojure-donts-lazy-effects
@mbarbieri: no problem. I've been bitten by this a few times where code running in my repl works (as the repl print phase forces realisation of the seq) but the code does nothing when I run it from an uberjar.
@agile_geek: ah that's why from uberjar it was not doing anything!!.... I was running it from repl for the same reason
as it runs reduce it would certainly realise the seq. Not sure what the advantages are over
doseq? Anyone know?
@agile_geek: the difference between doseq/map and run! it might be related to chunking and transducers.
FWIW, the above discussion prompted me to write about this problem domain in ClojureScript http://blog.fikesfarm.com/posts/2016-01-15-clojurescript-head-holding.html
@mfikes yep, just read your post. Very informative as my cljs knowledge is limited.
We are all beginners, especially with ClojureScript. Hope there aren't silly job postings requiring 5 years experience with it. :)
@mfikes I saw a job ad for 10 yrs Java experience in 1999! Even James Gosling couldn't have applied.
run! only returns
nil if the
proc function passed in returns
(run! identity (range 5)) produces
nil, for example.
if the service provides responses in JSON format, cheshire is a good parsing tool: https://github.com/dakrone/cheshire
Ah yes, so it is… https://clojurians.slack.com/archives/beginners/p1452891177006026
I have kind of a weird issue where hikari-cp is trying to make a connection to my database at compile time?