This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-03-26
Channels
- # announcements (6)
- # beginners (51)
- # cider (3)
- # cljsrn (9)
- # clojure (4)
- # clojure-argentina (1)
- # clojure-houston (2)
- # clojure-italy (5)
- # clojure-nl (1)
- # clojure-spec (14)
- # clojurescript (17)
- # community-development (2)
- # cursive (53)
- # datomic (69)
- # fulcro (5)
- # graphql (15)
- # immutant (6)
- # jobs (2)
- # kaocha (1)
- # leiningen (15)
- # lumo (5)
- # midje (1)
- # nrepl (6)
- # off-topic (119)
- # pathom (11)
- # tools-deps (5)
@noisesmith like the CLR (common language runtime)?
Ahhh, that says it is written on .net
and clojurescript on js yeah
I am reading about Graal for native machine code compilations
I should try writing a performance test to see how much faster Graal could be?
It sounds like a bad idea? I thought Java Virtual Machine only ran bytecode?
I've got a bit of code that produces a map from a list of maps, where each of those original maps has a value i'm using as the key in the produced map. e.g, turning [{:id 1 :name "foo" :tag "wee"} {:id 2 :name "bar" :tag "splat"}]
into {1 {:id 1 :name "foo" :tag "wee"} 2 {:id 2 :name "bar" :tag "splat"}}
that's good @robertfrederickwarner. You can generalize it, too:
(defn into-map
[keyf valf coll]
(reduce (fn [m v]
(assoc m (keyf v) (valf v)))
{}
coll))
(def d [{:id 1 :name "foo" :tag "wee"} {:id 2 :name "bar" :tag "splat"}])
(group-by :id d)
=> {1 [{:id 1, :name "foo", :tag "wee"}], 2 [{:id 2, :name "bar", :tag "splat"}]}
This works, but might not be what you want. Group-by assumes you might have duplicates, so you get a vector of maps back instead of oneThanks! Yeah group-by
isn't quite the right fit here (I'm converting results from a db query into a lookup, so I know there are no dupes), but another handy function to know about
or even:
(defn index-by
([keyf coll]
(index-by keyf identity coll))
([keyf valf coll]
(reduce (fn [m v]
(let [k (keyf v)]
(if (find m k)
(throw (ex-info "Duplicate key" {:k k}))
(assoc m k (valf v)))))
{}
coll))
([keyf valf mergef coll]
(reduce (fn [m v]
(let [k (keyf v)]
(if-let [entry (find m k)]
(assoc m k (mergef (val entry) (valf v)))
(assoc m k (valf v)))))
{}
coll)))
i ran across this tweet this morning: "A Clojure love story: Presses "p" in a specific place in the file. Now the program runs faster. The end." What would he be referring to here? Is this a clojure way to make something "parallel" or something?
cool, thanks! I'm far from needing to learn optimizations and such at this point but it's still fun to explore
there are no magic bullets in programming. (Implicit) parallelisation is no exception to the rule
I think I linked it here a dozen of times, but http://clojure-goes-fast.com/blog/ is quite insightful about performance
Maybe a bit of a stupid question, I am using a wrapper around java.time that wraps java.time’s exception into an ExceptionInfo. Can I catch warpped exceptions more specifically then just catching ExceptionInfo (or Exception, or …)
@lennart.buit (try ... (catch ExceptionInfo ....) (catch Exception ...))
works
I forget if it goes with first match or most precise, but I always order them narrow to wide regardless
right, catching Exception
works in my case, I was just wondering whether there was a way to be more specific about what wrapped exception I was expecting. Having been taught to always catch the most specific one ^^
you can't even catch a wrapped exception - you catch something and then check if it wraps something
you could write a macro that makes it look like you are catching a wrapped exception I guess
right, thanks
I think I’ll check the cause, and if it doesn’t make sense, just re-raise it
for the error reporting to pick it up ^^
yeah, that's how I always do a selective catch that can't just go on the type
try / catch / maybe throw
I have some scripts that I need to run. I am on osx. What command do I need to run? I know a super beginner questions
@bmaddy adding a solution for the nested group-by above:
(defn nest-by
[ks coll]
(reduce
(fn [m x] (update-in m ((apply juxt ks) x) (fnil conj []) x))
{}
coll))
this avoids the recursion. Feels right to use update-in for this and I find this solution beautiful (from s.o. so not my creation)@undothis When you say "scripts", do you mean Clojure or something else?
I basically got src, results, project.cjl, lib folders and I have no idea how to run it. hopefully that makes sense
I am using an Apple by the way. So I CD into the folder and type that in?
@undothis That sounds like a Leiningen project (because of project.clj
). Do you have Leiningen installed?
It sounds like you need to work through some intro-to-Clojure material starting from the basics (getting Leiningen installed, running a REPL, creating a new project from scratch or with Leiningen). Have you looked at Clojure for the Brave and True? Both a book and an online tutorial.