This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-10-15
Channels
- # 100-days-of-code (3)
- # announcements (14)
- # beginners (100)
- # calva (20)
- # cider (50)
- # cljdoc (29)
- # cljs-dev (6)
- # clojure (78)
- # clojure-europe (1)
- # clojure-italy (8)
- # clojure-losangeles (1)
- # clojure-nl (11)
- # clojure-uk (108)
- # clojurescript (23)
- # code-reviews (5)
- # cursive (7)
- # datomic (11)
- # devops (1)
- # editors (1)
- # figwheel-main (65)
- # fulcro (114)
- # hoplon (31)
- # hyperfiddle (1)
- # juxt (4)
- # lein-figwheel (2)
- # nrepl (13)
- # off-topic (72)
- # re-frame (35)
- # reagent (9)
- # shadow-cljs (42)
- # spacemacs (2)
- # specter (5)
- # tools-deps (60)
- # yada (2)
Does cider have problems when using clojure 1.9 version?
not that i'm aware of. what are your symptoms? @cybersapiens97
@dpsutton i've upgraded cider version and everything broke, now i reinstalled, lein repl command is working fine with my project on clojure version 1.9.0, but cider is saying `[WARNING] No nREPL middleware descriptor in metadata of #'cider.nrepl/wrap-version, see clojure.tools.middleware/set-descriptor!
cider switches to and autoinjects newer versions of piggieback and nrepl. these were old and untouched and nrepl was contrib and stagnant. you should (TM) be able to switch any of these dependencies you might have to the nrepl or cider versions
thanks @dpsutton i tried to re-do some changes and seems to be working
also, anyone knows how can i use Spec/keys in a way that i could say that a bunch of keys are going to have the same value. because i don't want to write (spec/keys [::a ::b ::c ... ::h]) and they all have the same value....
@cybersapiens97 Wrap it with s/and
and you can write any predicate you want to check the values.
thanks, i've managed to make the spec, but when the data is supposed to be (valid?) true, it throws an nullpointer exception, but when it's not (valid?) it gives me false without errors. How weird...
Is there any reason that run!
does not accept multiple sequences?
We can't write
(run! (fn [a b] ...) seq-a seq-b)
Instead, we have to use
(dorun (map (fn [a b] ...) seq-a seq-b))
or
(run! (fn [[a b]] ...)
(map vector seq-a seq-b)
Admittedly, these are both still clear code, but still not as nice as the obvious version above.Andre wrote an interesting article touching on this subject https://hackernoon.com/faster-clojure-reduce-57a104448ea4
Hi. Does anyone have a hint as to why (keyword "moo")
gets expanded to :moo/moo
after update
instead of simply :moo
as when it's printed just before?
(prn
(-> {:foo "moo"}
(update :foo (fn [e]
(prn "UE" e (keyword e))
(cond-> e
(string? e)
(keyword e))))
(update :foo (fn [e]
(prn "UE2" e (keyword e))
[:foo e]))))
;; "UE" "moo" :moo
;; "UE2" :moo/moo :moo/moo
;; {:foo [:foo :moo/moo]}
Nevermind. The (keyword e)
inside the cond->
needs to be just keyword
:face_with_rolling_eyes:
i'm profiling an application using visualvm; i'd like to repeatedly run a long-running operation. the first run takes a good long time, but for the second, the results are cached, so it doesn't.
* i should say, it's not that i'm repeatedly running the same operation, it's that i'm running the operation, changing a thing, running it again. etc.
oh. cancel that. I thought caching was happening, but actually it was just a 200x speedup.
@mfikes - Indeed, and a very interesting article, thanks.
But, this really just begs the question. Andre's article shows that this is doable, but far to complex to embed in user-level code.
So, the question remains: is there any good reason not to handle this in in reduce
and some key core users of it, like run!
?
I guess this would have to do with having to process two Arbitrarily large data (collections in this case). The way I’ve learned, there is 3 ways you can do this, based on the problem at hand: 1. One of the collections are dominant, therefore you don’t need to actually process the other one, so you can treat it as atomic data. 2. Both collections are about the same data and length and needs to be processed in parallel manner (I think map supports this) 3. The collections are not about the same data and length, and needs to be processed considering every type of input at each iteration. Case 1 and 2 are easy to implement, because the structure of the function is totally based on any of the collections. But in case 3, I think there lies the problems when dealing with reduce and other high order functions, because you would need to supply more base cases than it has on the structure implementation...
What are some good resources on Data-driven/Declarative
programming? I've seen Integrant and Reitit both describe themselves as data-driven and heard data > functions > macros
banded about but I don't know what the benefits are.
this might be of interest: https://www.youtube.com/watch?v=3oQTSP4FngY
Any good guides on how to organize tests that deal with stateful external systems? E.g. setup a test db, then tear it down after all tests run.
Not sure about guides, but per test-ns you can use clojure.test fixtures to setup a db and rollback/teardown after individual tests or once per ns
Stuart Sierra has also written a nice thing about fixtures here: https://stuartsierra.com/2016/05/19/fixtures-as-caches
I have some DevOps questions about Clojure. I want to have these pre-commit configurations where on every engineers' commit it does run a couple of Lein plugins (Kibit, Yagni, Eastwood etc) My git structure has many micro projects. Had the idea to create another project just to include these plugins and run by it, BUT, this didn't work. How to make it happen?
with the lein modules plugin you can use lein modules eastwood
etc. https://github.com/jcrossley3/lein-modules
Hi all, I'm also learning functional programming with Clojure. I did some practice on Hacker Rank functional path And created a bunch of PRs. So if anyone like to review Clojure code, it would be awesome! I'm still a beginner and feedback is always welcome 🙂 https://github.com/LeandroTk/learning-functional/pulls
@TK - one quick note, (fn [n] 1)
, the convention is to use _
for bindings that aren't used (fn [_] 1)
, but in the specific case of ignoring all args and returning a constant value, there's constantly
(constantly 1)
in the second one, (fn [x] (f x))
can always be replaced by f
so instead of (filter (fn [x] (odd? x)) coll)
you get (filter odd? coll)
also, filter
is not a macro, despite what the 7th pr says
on the 6th pr, (* (* (first original-list) 2) -1)
could be replaced by (* (first original-list) 2 -1)
or better yet (* (first original-list) -2)
also, any loop
that always consumes the next item of an input list at every step until the input list is empty should be rewritten as a reduce
, since reduce always has this behavior and that makes your remaining code simpler
@leandrotk100 also, for similar puzzles plus a large number of existing clojure answers to compare yours to, check out http://www.4clojure.com/
also, for the reverse function, check this out: (reduce conj () lst)
- it's worth stepping through and seeing how something that concise replaces the logic of your multi line loop calls
as a more advanced thing, (into () lst)
, since the two arg version of into
encapsulates (reduce conj ...)
into a single function
I implemented a into
function using reduce
with conj
yesterday
https://github.com/LeandroTk/learning-functional/blob/master/clojure/reduce.clj
@leandrotk100 in that document you say
(conj (1 2 3) 4) --> (1 2 3 4)
- (conj (1 2 3) 4)
is (4 1 2 3)
, (conj [1 2 3] 4)
is [1 2 3 4]
it's a big gotcha for when you're first learning, [] and () don't conj in the same place
right - I was being generous there, figuring that was a list that was already constructed that printed in that form :D
because their internal structure is different, so the natural insertion point is different
conj
always attaches at the "natural" place, that is the most simple and efficient place for the data structure in question
with a set or hash-map, conj might even change the order of the structure
often your first step in a clojure algorithm is making sure your input and/or output are the best data structure for the task
that's why (into () coll)
acts as a reverse - linked lists build from back to front
I want to install Java on an Ubuntu machine to develop in Clojure/Leingen. Which package should I install: default-jre, openjdk-11-jre-headless or openjdk-8-jre-headless?
Unless you know you need jdk11 features for some reason, jdk8 is slightly better supported -- a few Clojure libraries have problems when compiled on jdk11 -- they are being updated, but there still might be a couple that trip you up out there.
got it, thanks @andy.fingerhut
I haven't used openjdk-8-jre-headless much myself, usually Oracle's binary release of JDK8. I believe at least some of the openjdk packages on Ubuntu may have old crypto certificates in them that can cause issues connecting via https to some servers.
@andy.fingerhut I see. I will give it a try and see if it works with my codebase. Thanks for the heads up.
What is the most idiomatic way to test for every? (not (nil?)) coll
?
@yogidevbear (every? some? coll)
Thanks Mike 🙂 I got the same response in another channel so definitely on the right track 👍
If I make a request from Server A to Server B I get java.lang.ClassCastException: io.undertow.io.UndertowInputStream cannot be cast to java.lang.String
. I can slurp
the body and we are back in business. But I dont need to slurp when making a request from Client A to Server B. Any idea why this could be happening?
sounds like your two requests are using different abstractions for communicating with the network
a String is easier to use (no need to slurp or whatever), but it doesn't do a good job of representing data arriving over time - an InputStream allows more flexibility
OK, sounds like cljs in one case, clj in the other
ah. just noticed subtle shift in nouns. server A -> server B. versus CLIENT A -> Server B
you can give slurp a URL string if you just want a string from the remote host
@dpsutton yeah I saw that too, but you can use cljs on a server or clj on a client
I dont understand. Why is the body of a request an InputStream in one and a clojure map in the other?
I was under the belief that the middleware in Server B would take care of slurping the body or what have you.
a middleware on a remote server can't provide a client on the other end of the network with anything but bytes
any abstraction that gives you something more useful (streams, strings, hash-maps, whatever) has to be on the client side
"the server" is making a request, as a client, isn't it?
right, so it gets bytes from another server. You could attach middleware on your http client, but that isn't there by default
creating a test right now
{"field": "value"}
test here
clojure.lang.PersistentArrayMap
creating a test right now
#object[io.undertow.io.UndertowInputStream 0x356a51ab io.undertow.io.UndertowInputStream@356a51ab]
is wrap-json-body somehow attached to your client?
I thought it was a ring middleware attached to an http server
From the docs The wrap-json-body middleware will parse the body of any request with a JSON content-type into a Clojure data structure, and assign it to the :body key.
OK, that's what it does when you attach it to a ring http server
it's not a middleware for your http client
you need something else for that