This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-03-15
Channels
- # aatree (1)
- # atlanta-clojurians (3)
- # beginners (112)
- # boot (4)
- # boot-dev (1)
- # bristol-clojurians (1)
- # cider (55)
- # cljs-dev (23)
- # cljsjs (1)
- # cljsrn (7)
- # clojars (24)
- # clojure (84)
- # clojure-brasil (1)
- # clojure-china (1)
- # clojure-italy (27)
- # clojure-norway (17)
- # clojure-romania (1)
- # clojure-spec (109)
- # clojure-uk (92)
- # clojurescript (94)
- # community-development (1)
- # core-matrix (1)
- # cursive (12)
- # datascript (1)
- # datomic (23)
- # figwheel (1)
- # fulcro (17)
- # hoplon (11)
- # jobs-discuss (3)
- # keechma (6)
- # lein-figwheel (4)
- # leiningen (79)
- # lumo (32)
- # mount (42)
- # off-topic (22)
- # onyx (13)
- # parinfer (30)
- # portkey (47)
- # powderkeg (1)
- # programming-beginners (24)
- # protorepl (3)
- # re-frame (16)
- # reagent (100)
- # ring-swagger (7)
- # shadow-cljs (134)
- # spacemacs (3)
- # sql (1)
- # tools-deps (48)
- # uncomplicate (1)
- # unrepl (14)
- # yada (1)
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
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: https://clojuredocs.org/clojure.core/promise
thanks.
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))
14
15 (println "Anything else ?")
16
17 (println "Press q to quit ")
18
19 (def yo (read-line))
20
21 (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))
@christian767 thank you !!
@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.
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 😉
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)
(handler)
(update :body slurp)
(generate-stream out))))
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? java.io.InputStream in) ,,,)
ah thanks
you can’t spec defmulti or defmethod
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.
sorry, I assumed you meant creating an s/fspec for it
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
:pre takes a collection of expressions
so usually is like {:pre [(s/valid? int? var1)] … }
no, I thought you meant something else
off the top of my head, I’m not sure if preconditions are checked in both defmulti and defmethod
well defmulti really takes the inputs to the multimethod dispatch function itself
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.
https://www.braveclojure.com/ is where I started.
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
.
Interesting. It just prints that it connects in the minibuffer, but does not open a buffer.
The buffer is buried and I can switch to it manually, though.
Yes, from a lein project.
@roelof Hello again. Give up on Haskell?
True, I've been big into the functional programming community for over a decade 😅
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.
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!
I think Onyx might embody the heart of the language in a lot of ways. So its worth looking into.
also Michael Drogalis talk is fantastic. Maybe watch that before doing anything else: https://youtu.be/kP8wImz-x4w
I think that was directed at me, coming from many years of Lisp, but new to Clojure this week.
So thanks 🙂
That was one of the best talks I ever saw
@mfiano np. That talk changed my perspective on a lot of things
@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
@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.
(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)
@mfiano Perhaps this setting http://cider.readthedocs.io/en/stable/using_the_repl/#behavior-on-connect
@seancorfield's solution worked. Thanks all.
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)
also this series of blog posts is really good: https://aphyr.com/tags/Clojure-from-the-ground-up
A +1 for Living Clojure.
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 .} )
(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.
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)))
nil
user=>
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. https://github.com/mfikes/planck/commit/f16e6187f09a0201b3b2cefbfd8e0c1d75fa053d?w=1
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...