Fork me on GitHub

I have a vector maps called my-map like this [{:guid 123, :amount 100} {:guid 124, :amount 200}] I want to get a vector that looks like this [123 124], I tried this (map my-map [:guid]) but I’m getting the error IllegalArgumentException Key must be integer. Is there a different way to accomplish this when the value is a string rather than a number?


@josmith2016 "my-map" isn't a map, it's a vector


(map :guid my-map)


or if you have a string instead of a keyword, (map #(get % s) v)


Duh that's right, thanks @noisesmith


it is equivalent to (deref response)


it means response is an atom and you want the value of the atom


actually i lied. this is something from http-kit? it’s doing something I’m not familiar with


okay so it’s a clojure promise, not an atom:


Scripting is fun with clojure !


s Market)                                    4                                                5 (println "Preparing your basket")              6                                                7 (println "What do you want to add in your bask 8                                                9 (def basket [])                               10                                               11 (def item1 (read-line))                       12
13 (def c1 (conj basket item1))
15 (println "Anything else ?")
17 (println "Press q to quit ")
19 (def yo (read-line))
21 (if (= yo "q") System/exit 0) 


My code giving error : Unable to find static field exit


It’s a function


(System/exit 0)


(if (= yo "q") (System/exit 0))


for readability I would suggest using when instead of if when there is no else clause: (when (= yo "q") (System/exit 0))


@suryapjr you usually shouldn't use System/exit - this will kill your REPL. It's almost always better to just return and let the program finish.


Guys..why should we write concurrent code ?


Practical examples..


Trying to understand how to implement future


in a leiningen project, how would I go about printing the dependency tree that will be visible to the user of my lib once I deploy it to clojars? Doing lein with-profiles -dev deps :tree still seems to add things like clojure-complete and org.clojure/tools.nrepl etc. I realize this probably should be in #leiningen, but that channel seems a bit stale


@suryapjr That’s an extremely broad questions, you could write books about it 🙂 Mainly you write concurrent code because computers nowadays have more than 1 CPUs/cores, so you could be using them to get faster execution of your program. Not all problems can be solved this way, and even for those who can, historically it has been hard to write concurrent code without bugs, because the primitives exposed e.g. Threads and Locks are very hard to reason about once your program grows in size. Clojure provides higher-level primitives like atoms, promises, futures, agents etc. to help write correct concurrent code.


@U7PBP4UVA the way I see it, what you're describing is parallelism, not concurrency. Concurrency is when several logical processes access common resources, which has more to do with the purpose of the program. A single threaded program can be concurrent!


Heh, the old concurrency vs parallelism thingy 🙂 Very true, and I like the idea of logical process & common resources. Stealing this for some future explanation 😉


Thank you gentlemen.


Hello, quick question which I can't seem to find the answer to. I am slurping a body stream in my ring handler so I can convert it to a string, but I would like to first check if it is a stream to prevent failure, because sometimes the body can be string and sometimes it's an input stream. How would I do that?


currently my code looks like

(def handler (wrap-apigw-lambda-proxy api))

(deflambdafn api.lambda.Handler
  [in out ctx]
  (with-open [in (io/reader in :encoding "UTF-8") out (io/writer out)]
    (-> (parse-stream in true)
        (update :body slurp)
        (generate-stream out))))

Russ Olsen13:03:56

If you can deal with the logic as "if this is string do this otherwise assume it's a stream" you can also use the string? function, which in my mind is just a little tidier. And it's probably complete overkill here but you could also create a multimethod. Yes, that would be utter overkill.


Try (if (instance? in) ,,,)

Alex Miller (Clojure team)14:03:17

you can’t spec defmulti or defmethod

Alex Miller (Clojure team)14:03:48

you can spec the dispatch function in defmulti if you extract it to a function in a var


@alexmiller I updated the first code snipped to reflect what :oneoption is.

Alex Miller (Clojure team)14:03:35

sorry, I assumed you meant creating an s/fspec for it

Alex Miller (Clojure team)14:03:22

the syntax you’re using for preconditions there isn’t right btw


@alexmiller I might not have written here correctly trying to anonymize my code

Alex Miller (Clojure team)14:03:57

:pre takes a collection of expressions

Alex Miller (Clojure team)14:03:17

so usually is like {:pre [(s/valid? int? var1)] … }


Does your statement for defmulti still stand, though?

Alex Miller (Clojure team)14:03:38

no, I thought you meant something else

Alex Miller (Clojure team)14:03:09

off the top of my head, I’m not sure if preconditions are checked in both defmulti and defmethod


So either one or the other suffices?

Alex Miller (Clojure team)14:03:57

well defmulti really takes the inputs to the multimethod dispatch function itself

Alex Miller (Clojure team)14:03:11

defmethod is really the function called as a result of the defmulti dispatch method


@alexmiller thank you for your help! It has clarified some of the spec issues I've had.


what is the best way to learn clojure for a complete beginner

Michael Fiano17:03:18

For those using Emacs, is cider-jack-in supposed to open the REPL also, or just connect to it? I'm Reading "Clojure for the Brave and True", and it mentions that it should also open a REPL, but it does not for me. I must also run cider-switch-to-repl-buffer.


cider-jack-in opens another window for me, along with starting a REPL.

Michael Fiano17:03:47

Interesting. It just prints that it connects in the minibuffer, but does not open a buffer.


At least when opening from the context of a lein project

Michael Fiano17:03:01

The buffer is buried and I can switch to it manually, though.

Michael Fiano17:03:10

Yes, from a lein project.

Michael Fiano17:03:34

@roelof Hello again. Give up on Haskell?


nope, but always curious about others languages


@mfiano you are also everywhere

Michael Fiano17:03:30

True, I've been big into the functional programming community for over a decade 😅


oke, why did you change clojure to haskell then ?

Michael Fiano17:03:29

I'll always be at home with Lisp. Treating data as code and code as data allows for expressive code, easy refactoring, and meta-programming that just isn't possible with other languages.


oke, I did a some ruby, little scala, little c# and some haskell


but I find nowhere really my home

Drew Verlee20:03:45

If you have a strong background already i think… start with “living clojure” then read: “joy of clojure” and “elements of clojure” and “clojure applied” all at once. Mixin what ever other stuff you want!

Drew Verlee20:03:09

I think Onyx might embody the heart of the language in a lot of ways. So its worth looking into.

Drew Verlee20:03:08

also Michael Drogalis talk is fantastic. Maybe watch that before doing anything else:


do not think that is something for a complete beginner in clojure but interressting

Michael Fiano03:03:04

I think that was directed at me, coming from many years of Lisp, but new to Clojure this week.

Michael Fiano03:03:10

So thanks 🙂

Michael Fiano15:03:40

That was one of the best talks I ever saw

Drew Verlee21:03:11

@mfiano np. That talk changed my perspective on a lot of things


For me I cannot find a language which it totally good for me. So I can settle


@mfiano you say the repl window is buried, but is it actually connected and working? Is there anything written to *nrepl-messages* or *Messages* that suggests a failure? I’m about to go afk for an hour but that’s where I would start. You can take this discussion to #cider where others can surely pitch in

Michael Fiano17:03:33

@gonewest818 Yes, it is connected. I can switch to the repl buffer and use it just fine. It's just that it is not opened when I call cider-jack-in from a lein project.

Michael Fiano17:03:47

(It only connects to it when I call that)


@mfiano Sounds like an Emacs setting needs updating to auto-switch to the REPL buffer when it is opened. It sounds familiar but it's been a few years since I used Emacs... There is an #emacs channel if you want to try their or #cider perhaps?


(ah, I see @gonewest818 already suggested the latter)


Michael did you follow the setup guide for emacs from brave and true?

Michael Fiano18:03:56

@seancorfield's solution worked. Thanks all.

Drew Verlee19:03:26

I wonder if there would be interest in a remote meet up and discussion around the Elements of Clojure book which is having a full release this week (crosses fingers)


no more recommendations for learning clojure as a beginner ?


heard good things about Living Clojure, and can recommend Programming Clojure


also this series of blog posts is really good:


A +1 for Living Clojure.


thanks all


hey guys, just a noob question… how do I remove a map from my list based in another list?

(def bl '({:lemma the, :pos DT} {:lemma dog, :pos NNS} {:lemma be, :pos VBD} {:lemma dog, :pos VBG} {:lemma around, :pos RB} {:lemma ., :pos .})
(def st '(the be around))

expected output: ({:lemma dog, :pos NNS} {:lemma dog, :pos VBG}  {:lemma ., :pos .}  )


I tried with remove and filter but didn’t work the way I was expecting.

Steve C21:03:23

you can use filter. You'll want to make st a set


(filter (comp #{"the" "be" "around"} :lemma)
        '({:lemma "the" :pos "DT"} {:lemma "dog" :pos "NNS"} {:lemma "be" :pos "VBD"}
          {:lemma "dog" :pos "VBG"} {:lemma "around" :pos "RB"} {:lemma ".," :pos "."}))
({:lemma "the", :pos "DT"}
 {:lemma "be", :pos "VBD"}
 {:lemma "around", :pos "RB"})


comp is compose. so filter by first calling :lemma and then the set with what you are looking for in the lemmas.

λustin f(n)23:03:58

I have been told there is a way to inspect the source of an existing function in-repl. Is this Truth? How do?


@austin021 usually just (source my-func)


(! 688)-> clj
Clojure 1.9.0
user=> (source inc)
(defn inc
  "Returns a number one greater than num. Does not auto-promote
  longs, will throw on overflow. See also: inc'"
  {:inline (fn [x] `(. clojure.lang.Numbers (~(if *unchecked-math* 'unchecked_inc 'inc) ~x)))
   :added "1.2"}
  [x] (. clojure.lang.Numbers (inc x)))

λustin f(n)23:03:21

Just what I was thinking of, thanks!


The function has to have been loaded in from a source file -- it doesn't work with functions just typed in at the REPL.


^ FWIW, we added that to Lumo and Planck... it is a great convenience, that could perhaps be in all REPLs 🙂


Is it much work to add function sources to a repl @mfikes?


@seancorfield It wasn't that difficult in ClojureScript, as we just stashed the source in the AST, and fetched it from there.


Hmm, source-fn looks for :file metadata and then reads the source file... 👀


I revised that URL to only show the non-whitespace change to show how simple it really was


It is probably worth an hour spiking it in the Clojure REPL to see if it pans out there 🙂


Hah, yeah, in one of my many "spare" hours... 🙂


But maybe I'll try to scratch that itch at some point...


You'll gain them back when typing source for REPL entered forms 🙂