This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-08-04
Channels
- # aleph (4)
- # bangalore-clj (1)
- # beginners (89)
- # boot (16)
- # braveandtrue (4)
- # cider (1)
- # cljs-dev (6)
- # cljsrn (90)
- # clojure (132)
- # clojure-austin (1)
- # clojure-dusseldorf (4)
- # clojure-italy (12)
- # clojure-portugal (2)
- # clojure-spec (13)
- # clojure-uk (41)
- # clojurescript (142)
- # code-reviews (19)
- # conf-proposals (1)
- # datascript (6)
- # datomic (7)
- # graphql (12)
- # jobs-discuss (3)
- # keechma (23)
- # leiningen (3)
- # lumo (22)
- # off-topic (7)
- # om (21)
- # onyx (8)
- # parinfer (46)
- # pedestal (3)
- # perun (3)
- # re-frame (10)
- # reagent (30)
- # ring (1)
- # rum (2)
- # spacemacs (1)
- # sql (2)
- # testing (17)
- # yada (32)
@lxsameer You will have a problem with middlewares that modify responses if you want to return deferreds from you handlers
anyone familiar with hcitool lescan
?
Any recommendations on a Clojure library for Kafka integration?
@noisesmith thanks man
@yonatanel please do tell, So on top of my head you need to deref the response and generate a new one in middlewares right ?
Well yeah but once you deref you are already blocking. You need to fork the middleware where appropriate if you want not to block.
I think its logging is silent in comparison with jetty. I can't remember how I configured it.
@misha you're right. transients exist because sometimes you don't need intermediate objects so you improve perf by not constructing them in case of a linked list, intermediate objects are part of the final structure, so basically there's nothing to improve
@leonoel makes sense, than you.
do you happen to know which is faster/preferred from any pov: (list)
or '()
?
how can I have a spec that makes sure the value is a datetime? (a string with an iso formatted datetime value in it). With a regex or is there something better?
@leonoel btw you don't need to use '(), it accepts ()
I've got an exercise I can't figure up an elegant solution for: Let S be a sequence of sets. Compute R the sequence of sets such that each element of R is equal to the element of S at the same position, but also shares no elements with any sets that exist before that position in S.
@bcbradley so does this mean taking the subset of each set in the series that consists of the elements not seen in any of the sets so far?
@noisesmith yeah, almost-- "not seen in any of the sets so far (EXCEPT the current one)"
(defn f
([sets] (f sets #{}))
([sets seen]
(when-let [[set & sets] (seq sets)]
(cons (into #{} (remove seen) set)
(lazy-seq (f sets (into seen set)))))))
i wonder how others might try it, there seem to be bunches of ways; i've spent a lot of my free time recently just trying to come up with new ways xd
+user=> (:acc (reduce (fn [{:keys [acc seen] :as state} s] (-> state (update :acc conj (set/difference s seen)) (update :seen into s))) {:acc [] :seen #{}} [#{1 2} #{2 3} #{1 2 4 5} #{1 4 5}]))
[#{1 2} #{3} #{4 5} #{}]
the lazy-seq version is nicer
hmm one could also whip up something using reductions
: (map (fn [r seen] (set/difference r seen)) r (reductions into #{} r))
(untested)
transducer version :
(defn xf [rf]
(let [seen (volatile! #{})]
(fn
([] (rf))
([r] (rf r))
([r s]
(let [xf (remove @seen)]
(vswap! seen into s)
(rf r (into #{} xf s)))))))
might as well show the prettier version of mine
+user=> (->> [#{1 2} #{2 3} #{1 2 4 5} #{1 4 5}]
(reduce (fn [{:keys [acc seen] :as state} s]
(-> state
(update :acc conj (set/difference s seen))
(update :seen into s)))
{:acc [] :seen #{}})
(:acc))
[#{1 2} #{3} #{4 5} #{}]
Clojuredocs question (I don't know whom to ask really):
a number of pages appear to only work with clojure.data.xml
but the examples use (or require) clojure.xml
.
The codes appears wrong on pages like this. Should this be edited or is it correct as-is? e.g. https://clojuredocs.org/clojure.zip/edit
I have a hunch astro’s would be if it used (into #{} (remove …) …) instead of remove / set
it's actually the same solution as @the-kenny , once cleaned up
yeah, I’d use into
instead of set/union in 100% of cases
and actually into with a remove transducer can easily replace set/difference
(set/difference a b)
becomes (into #{} (remove (partial contains? b)) a)
I mean with reductions you can't efficiently use transients as every steps needs to be persisted
@bcbradley I think you meant your problem to state that “…each element of R contains all and only those elements of the lement of S at the same position which are not seen in any sets that exist before that position in S”? Otherwise e.g. in noisesmith’s solution example you should expect [#{1 2} #{2 3} #{1 2 4 5} #{1 4 5}] => [#{1 2}] since all sets of R must be equal to their respective positioned elements in S
@kingcode right - I read it that way at first but the problem statement didn’t seem coherent
so I made some assumptions
yeah - they should all calculate the same way
@bcbradley I think this would be a nice candidate to http://4clojure.com
@bcbradley Great…hopefully they will respond. I did submit a “Towers of Hanoi” candidate months ago, but never saw it added, or heard from anyone.
My solution is similar to noisesmith: (fn [sets] (-> (fn [[r seen] s] [(conj r (clojure.set/difference s seen)), (into seen s)]) (reduce [[] #{}] sets) first))
@kingcode you can surround your code with ` (triple backtick) to get it to format properly
Haah, thanks @bcbradley!
Sorry for the verbosity, making my code snippet pretti..er:
(fn [sets]
(-> (fn [[r seen] s]
[(conj r (clojure.set/difference s seen)),
(into seen s)])
(reduce [[] #{}] sets)
first))
It’s not very compact/elegant, but probably fast enough…am studying others’ and learning.
Great problem, thanks for sharing - what name did you give it on http://4clojure.com? I will watch for it…
I didn't think to give it a name, I just described the problem and example input and output data in a message on freenode
clojure is so compact and elegant as a language there are probably hundreds of ways to solve even a problem the average solution length of which 8 lines; i think there is a ton to learn from simple problems like that one, regardless of whether you are super new to clojure or super experienced with it
for instance, drowsy's approach involves a fairly novel use of reductions with sets that i haven't seen before
aw OK….you might want to register/login and to the “Submit a problem” tab on http://4clojure.com itself..
Once logged in, you should see two navigation rows at the top. The second row should have ‘Account Settings’, ‘Leagues’, and ‘Submit a Problem’..
not for me, but you are free to submit the problem if you'd like (or anyone else, you don't have to bother giving me credit-- name it whatever you want :d)
what’s the correct way to place a async/dropping-buffer
in a async/pub
and a bunch of async/sub
s?
quick Q: How can one build vars in a macro? I have a spec that I want to turn into a symbol within a macro (e.g.: (defaction ::some-spec ..)
should result in a function (defn make-some-spec ..)
but not sure how to go about constructing the make-some-spec
symbol
... it's always when you finally type something out that you figure out the solution.. nevermind >.<
@dadair haha - (comp symbol name)
is an elegant choice
err, I guess you need to use str in there too
I do know that if I place a dropping-buffer in all three places, I get a NoSuchElementException internally in core.async
@csm put it on b, that way either a or c (or both) could be passed in by the code creating it
which is a nice pattern, it lets consumers decide what transducers should be on a channel, etc. or how much buffering they need based on activity patterns
b, the one in the middle, is the one that code would always own, so it’s the sensible place for things it specifically should define
the use-case is to partition a stream by a key, then to further partition/batch items via a transducer per sub
@bcbradley strange…perhaps you just need to submit a few exercises ‘ solutions? I’d be happy to submit it for you if you prefer.
(every? keyword? [])
=> true
^^^ Seems counterintuitive to me… I would think this should be false (or nil). I suppose you could see it both ways, but if there are no elements then every element isn’t a keyword. I suppose it’s a not a big deal but wondering if others have the same intuition as me or if I’m crazy 🙂I've always translated every?
to mean that there are no values for which the predicate is not true
. So this makes perfect sense to me.
This might be akin to Stockholm syndrome though....
I guess it depends on your perspective… like the blind men and the elephant. Anyway, it bit me this afternoon and thought I’d share.
This is not Clojure - specific :) a lot of logical paradoxes would arise if this was not the case
A nice consequence of this is (= (every? p (concat coll1 coll2)) (and (every? p coll1) (every? p coll2))) for any 2 collections coll1 and coll2
Ah, gotcha. Makes sense. Thanks @U06GS6P1N
Thanks for the link @U0NCTKEV8 I’ll read it over. I figured there was a reason
Hey, can't believe I haven't hit this before, is there something like swap!
, except that it can return an extra value?
like, [new-state other-value]
... Or would I have to build that with compare-and-set!
?
you can write it yourself using compare-and-set!
heh, yup
there’s also using refs and returning the relevant data from your transaction
since caring about two values at once can be a sign that the values should be coordinated and that’s what refs are for
This was working two weeks ago, breaks today when I launch CIDER from within the project.
error in process sentinel: Could not start nREPL server: Could not find artifact org.clojure:clojure.math.numeric-tower:jar:0.0.4 in central ( )
Could not find artifact org.clojure:clojure.math.numeric-tower:jar:0.0.4 in clojars ( )
This could be due to a typo in :dependencies or network issues.
If you are behind a proxy, try setting the ’http_proxy’ environment variable.
Per
, there has been no change in version number. No change to my files, either. Everything else here seems to be working fine, network-wise. And other dependencies load fine if I comment this one out.
Ideas how to proceed?are you sure there isn’t a hidden typo? https://mvnrepository.com/artifact/org.clojure/math.numeric-tower - maven claims that 0.0.4 is available
oh yeah - there’s one too many clojures in there
remove the second “clojure”
I'm trying to make a lib out of a "predicates by example" functionality I regulary use. So any feedback is welcome: https://github.com/IamDrowsy/ebenbild/