Fork me on GitHub

I would likely use group-by, which is more general


It accounts for multiple entries under the same key


You may also want to look at clojure.set/index


@timgilbert how do plan to use the result? because a simple group-by could suffice (especially if you have duplicate keys):

=> (def xs [{:a 42 :b 4 :c 5} {:a 32 :b 1 :d 5} {:a 12 :b 23 :c 76 :g 5} {:a 34 :b 4 :c 6}])

=> (group-by :a xs)
{42 [{:a 42, :b 4, :c 5}], 32 [{:a 32, :b 1, :d 5}], 12 [{:a 12, :b 23, :c 76, :g 5}], 34 [{:a 34, :b 4, :c 6}]}

Drew Verlee02:02:16

Anyone have a software conference or talk they would recommend? Preferable something i could watch on youtube. It doesn’t have to be clojure related 🙂


@drewverlee I recommend this one, probably the best talk I've ever seen:

Drew Verlee03:02:28

Oh boy, "to the moon" was not an ideal watch before bed. Im all sorts of reved up.

Drew Verlee03:02:45

Great talk! Thanks for the suggestion


@timgilbert does this do what you want?

(zipmap (map :product-manufacturer/slug manufacturers)


Yes, that’s perfect! Thanks @alexbaranosky (and everyone else who offered suggestions). The (group-by) example is almost perfect too, but I’d rather have {1 {:x 1}} than {1 [{:x 1}]}


FWIW, the keys I want to use for the top-level map (`:x` in the above example) are unique in the seq of maps I’m transforming


yeah my solution assumed :product-manufacturer/slug is a unique identifier


otherwise you'd lose entries


How to enable this team's IRC gateway?


What would be the right channel to discuss "what is the ideal way to setup auto completion in clojure? using static methods [analyzing source code] or dynamic methods [querying a repl]?"


@qqq: you could ask folks in #cider how auto completion works in emacs.


@qqq check out the cider nrepl project, there's a complete "op" that it adds. I believe it's backed by a library called completion.


does anyone know the difference between using reader macro ^ to assign metadata vs with-meta? I’m using clojure 1.8


that’s what I’m observing:

(meta (:foo {:foo (with-meta str {:optional true})})) => {:optional true}
(meta (:foo {:foo ^{:optional true} str})) => nil
(meta (:foo {:foo ^:optional str})) => nil


I’ve read the doc (, but didn’t find anything regarding this behavior...


@residentsummer I'd guess the reader macro assigns the meta to the symbol itself, not the value it'd resolve to


(defmacro x [y]
  (println (meta y))
  `(println (meta ~y)))

(let [asdf 10]
  (x ^:optional asdf))
;; => {:optional true}
;; => nil


IMHO this is seriously limit the usefulness of metadata...


how come?


I was trying to implement a somewhat unified http params parsing in my request handlers with something like this

(-> handler
     {:start_date my-date-parser
      :end_date ^:optional my-date-parser}))


and if metadata is applied to symbols, I have go some other route...


if wrap-parse-params is a macro, you can see the meta


otherwise, you can use with-meta, or just express the 'optional' part as pure data


Yeah, I’ve initially went with the data way (well, kind of). Just tried to add some visual appeal and remove a ton of (:require [my.middleware :refer [optional default]]). Now it looks like {:end (optional my-date-parser)}


you could do [:optional my-date-parser]


or, if optional is the only meta, something like

  :required {...}
  :optional {...})


Well, I can do it with macro… But the last time I touched them, I woke up in the macro hell 😄 Vector variant looks promising, though. Thank you for suggestions!


yeah, pure data is almost always preferable imo


@tbaldridge really inspiring talk, thx for sharing


@tbaldridge holy moly, what a speech. thanks.


is there a clean way to convert (System/getProperty "file.separator") into a regex? I can't do (re-pattern (System/getProperty "file.separator")) because I guess you need four backslashes to escape it properly for re-pattern?, like (re-pattern "\\\\")


I could always just do a conditional check for windows or the backslash but at that point I might as well just hard each slash instead of even using file.separator


Ok I think (re-pattern (java.util.regex.Pattern/quote (System/getProperty "file.separator"))) is what I wanted


hi all. I have a problem with buffer loading / evaluation and multimethods. For example, I have

(defmulti my-multi (fn [switcher _] switcher))

(defmethod my-multi :first
  [_ arg1]
  (do-something-first arg1))

(defmethod my-multy :second
  [_ arg1]
  (do-something-second arg1))
I update it to
(defmulti my-multi (fn [switcher _ _] switcher))

(defmethod my-multi :first
  [_ arg1 arg2]
  (do-something-first arg1 arg2))

(defmethod my-multy :second
  [_ arg1 arg2]
  (do-something-second arg1 arg2))
then I load / eval buffer with C-c C-k (`cider-load-buffer`), or with cider-eval-buffer. But when method is called, I get clojure.lang.ArityException. The code lays in one file (and namespace), but is called from another. I tried to load / evaluate both buffers, but it doesn't help. Also, code is called from core.async if it matters. it is pretty uncomfortable to restart Clojure REPL each time I change arity of a multimethod...


@featalion there's a long rationale as to why, but the gist is the function in the defmulti is set once on the initial eval


2 ways to fix this: Put the function in a defn, then do (defmulti my-multi #'my-fn)


we were just making sure that this was a clojure limitation and not a CIDER defect


The other is to put (def my-multi nil) before the multimethod


here's the problem, if you put defmethods in other namespaces you'd have to re-eval those namespaces whenever the defmulti namespace is redefined. So in order to keep any of that from happening, re-evaluating a defmulti is a no-op


Granted, I would have preferred the other behavior, but many people disagree with me.


did something happen to namespace functions in 1.9.0? ns-map no longer tells me what I :required. I have (ns foo (:require [bar.baz])) and I need a way to discover that bar.baz was required.


You have to look at the source on git.


@tbaldridge thanks, I will try it! It seems acceptable during development to do so.


ugh. is there, with compojure-api, a special case for the "/" route? I used to have a index.html in /resources, which worked fine, but now I want to migrate that index.html to hiccup, and it doesn't match the '/' route


what am i doing wrong? Because if I change the "/" into "/something-else", and I turn my browser to localhost:3449/something-else, it DOES work.


so it seems the "/" is some special case


is this the case?


have you tried ""?


personally I prefer bidi because it's a bit easier to grok (IMO), but obviously this should work with compojure too


"/" should work, that's what I have in all the apps using compojure-api


my guess is you didn't completely restart your process, and didn't start the webserver in a way that allowed for live re-definition, so the server is still serving the original routes you defined


hiredman: i actually did restart the repl to be sure... haven't tried "" though...


hiredman may be on to something here


Question for current or previous Clojure beginners: What was the most difficult part(s) about getting into Clojure for you? The setup? Learning the actual language itself? Finding help? Figuring out how functional programming works? Or something else?.. I'm looking to put together a learning resource focuses on some of the pain points of getting started with Clojure to make things as seamless as possible for newbies. All help would be appreciated 😃 If you can, please use the 'start a thread' button on this post so we don't make clutter and keep things easy to find Thanks! 😃


lukecage: I've been programming in Clojure for a few years and so only have unreliable memories of being a beginner. But at my last job I coached a number of new people learning clojure when coming into our code base. The biggest problem that was common among all of these people was mutability


the idea of using map and reduce to build a new collection instead of doing some kind of manipulation of the existing sequence constantly had me telling me to stop reaching for atoms so they could do mutations


lukecage: It’s been a while for me, but when I was starting out, my primary problems were 1. using an editor without paredit 2. learning good architectural design patterns 3. debugging errors when realizing lazy seqs


For me it was finding a good editor, getting a good dev env setup, and figuring out how the JVM dependencies work. Most of that was solved for me via Cursive. I didn't have a emacs background so learning emacs made it hurt even worse. And I started on a Windows machine back when lein's support for windows was really bad.


As in any language though, I think a big bump is that part when a beginner says "so I finished Brave Clojure and done some 4clojure do I write something real?"


Coming from java I remember reading my first clojure book. And unpatient as I am I was waiting for the chapter that explained how classes can be used in clojure. Well, it took a few hours and some ruthless searching through the book until I understood that clojure has no concept of classes, but instead uses vecs / seqs and maps. After that I was pretty fine. The next bumper for me were understanding component from a concept point of view and getting a dev setup working that hot reloads every code. Especially the #'var part was very hard for me to understand as it is not easily searchable.


lazy stuff. still bites me in the butt occassionally. just the other day i spent an hour or two on a bug before realizing all i needed was doall.


I hear that @U0LGCREMU and it kindof-sortof-not-really gets better. I still have problems with that from time to time.


@tbaldridge i consider laziness a good feature: it reminds me every now and then that i'm not so smart after all. ;)


Makes me wonder sometimes if it wouldn't be better to teach beginners transducers first


the humility feature. every language should have one.


believe it or not i've still not gotten around to *ducers. having too much fun with metaprogramming.


dunno about first, but early. or were you being ironic?


nope, I was being serious. I've wondered if lazy seqs seem so familiar because we learned them first.


speculation: the distinction between eval strategy, and semantics, is a,major stumbling block for noobs.


laziness does not affect reasoning about meaning, but it does affect reasoning about comoutation. in languages without laziness this distinction never even comes up.


@U08PR8LJZ : the conceptual shift. we can all, dog-like, learn to perform tricks in a new language without really understanding much.


@U08PR8LJZ: the tallest mountain for me was mapping the real world projects, that I know, to Clojure: i.e. how do I do AOP in Clojure? how do I inject a datasource.. and where? how do I orchestrate the whole application? What it comes down to be is the difference between OOP and Clojure thinking: * OOP: Objects, delegation + message passing vs. * Clojure: data from A needs to transform and get to B It did not happen overnight, but once I started to think in data => pipeline => data => pipeline all the real world problems that I could not map to Clojure before suddenly mapped, almost like a thin thread orthogonal to all the OOP application layers with just data and functions.


for me, enlightenment came (not in a flash, gradually) when i realized that clojure was making me reconceptualize what the entire enterprise is all about.

Drew Verlee21:02:59

I dont think its possible together a “learn clojure path” that works for everyone. Everyone has a different starting point. How I would approach someone with 20 years of java experience is way different then someone new to software. Most of the struggle comes from helping people understand the tools their already using. Why do we mutate state? Why do we have classes? Why do we not share objects over the wire? I think “Clojure for the Brave” is fantastic for new comers. Perennially, as someone who hasn’t built a large system, i’m taking most of my notes from “Clojure Applied” Which seems to build an argument for various tools in the ecosystem which i had a hard time understanding before like protocals. It wasn’t that i didn’t understand what they did, but rather i didn’t understand why I would use them over a Map. I believe the answer is, to communicate intent to other developers. I think “Clojure Applied” gives a lot of insight into how to build a system, which for me, was the next big question after understanding the basics of clojure.


For me: "Figuring out how functional programming works?", definitely


It felt like my brain was rewiring itself

Drew Verlee05:02:58

I think many new programmers, including myself would actual have a harder time answering the question "Why use a OO language?” I found this talk by Bob Very helpful towards answering that question: the summery is that OO languages let you respond to change better through polymorphism, which lets you invert the flow of control of a program so that high level modules dont have to know about the implementation details of low level modules. I mention this because i want to re-enforce the idea that I think it would help a lot of programmers see the value in FP and clojure if they understood better the tools their currently using.


I am a year in and would still consider myself fairly “Beginner” Clojure is pretty easy, its figuring out the best way to do things that is hard — because it is quickly evolving and new libraries are constantly added, often the new way is the best way to do stuff- but the best documented stuff is older stuff. As a new learner looking for example code, I am going to find a lot more 2012 examples than 2016 examples,


On the clojurescript side, I feel that it “assumes” a pretty good understanding of the JavaScript host language. Interop is cool, but if it is necessary, then I need to learn 2 languages instead of one, and then learn how to twist the javascript, and that isn’t a comfortable learning curve.


I am probably fairly unusual in that I came to Clojure first, with only mild dabbling experience in other langages


Thank you everyone who replied. Lots of good info here!


hello guys, I bet this question has already been asked but my datomic console when launched with bin/console -p 8080 mbrainz datomic: (after install script) throw this error =>

Exception in thread "main" java.lang.IncompatibleClassChangeError: Implementing class...


baptiste-from-paris: Have you tried the #datomic channel? :-)


@scknkkrer : took a look, did not see anything obvious. i wonder if there is any way other than ns-map to discover what has been required/loaded in a namespace.


anyone remember the name of that lib that enables running lein tasks from the repl?


ahh alembic