This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-06-24
Channels
- # admin-announcements (2)
- # beginners (46)
- # boot (8)
- # cider (29)
- # cljs-dev (45)
- # cljsjs (10)
- # cljsrn (13)
- # clojure (60)
- # clojure-dev (5)
- # clojure-greece (1)
- # clojure-ireland (4)
- # clojure-mexico (6)
- # clojure-poland (3)
- # clojure-quebec (3)
- # clojure-russia (8)
- # clojure-spec (89)
- # clojure-uk (70)
- # clojurescript (84)
- # cursive (4)
- # datomic (7)
- # devcards (1)
- # dirac (2)
- # emacs (11)
- # hispano (10)
- # jobs (13)
- # keechma (34)
- # lein-figwheel (4)
- # luminus (19)
- # off-topic (2)
- # om (78)
- # onyx (6)
- # parinfer (1)
- # planck (82)
- # proton (2)
- # re-frame (10)
- # reagent (23)
- # ring-swagger (5)
- # spacemacs (2)
- # specter (24)
- # spirituality-ethics (122)
- # untangled (13)
i.e. I have {:foo 1 :bar 2 :baz 3 … :zzz 26}
, but each one of those keys is optional.
lwhorton: you could do it programmatically
I wrote a function called optionalize-key once
you could use it to optionalize all the keys via (reduce optionalize-key map-schema (keys map-schema))
any number of similar tactics would work too
Is there anything like a for
loop (allowing iteration over multiple variables) with reduce
-like accumulation rather than generating a seq?
I occasionally end up having to do nested reduces, where each level uses closed-over bindings from outer levels so I can’t easily extract them into reducing functions.
@cfleming: are you familiar with loop/recur
? It sounds like that's what you need, and I've used it before to un-nest multiple reduce
s.
@josh.freckleton: I could do that, but it’s a pain having to manage the seq iteration manually.
what do you mean? loop/recur
doesn't need to accumulate to a seq
...
@cfleming: could you be more specific about what you're trying to solve?
@josh.freckleton: What I mean is that if I use loop/recur, I need to use code like:
(loop [items (some-seq)
accumulator (some-initial-value)]
(if-not (seq items)
accumulator
(let [item (first items)]
(recur (rest items) (do-some-processing accumulator)))))
I'm not crystal clear what you're trying to solve, but I've had (what I assume are) similar situations that I've solved in one loop, where the loop keeps track of a few items, and then your conditional can be a cond
or case
that accounts for the multiple different items... would that help?
(WIP, contains bug right now where intermediate map levels are not created correctly, but you get the idea)
So here I’m iterating over modules, and within modules I’m iterating over namespaces.
It’s an ideal match for a for
loop, except I’d rather not create a potentially large intermediate seq just to do (into {})
That function is just too big, but I can’t trivially extract the reducing functions because they close over outer values.
I need to leave soon, so regrettaly dont have time to dig in. But to explain my solution to similar situations, imagine in your loop you have modules
and nss
, you only exit when both modules
, and nss
are empty. If nss
is not empty, process one, loop on the rest. If nss
is empty, then load the next module, fill up nss
for the next go-round, and process until both of those seq
s are empty.
This case isn’t too bad, but with another level (which I’ve had from time to time) it gets pretty hairy.
ya, I think my solution is an elegant way have handling arbitrarily many seq
s to loop over
(if I'm understanding)
Sure, but like I say, you end up with a lot of manual seq management - I’ll try it, but I suspect that it’ll be a wash.
no problem, I hope it helps! is my proposal clear? it would look something like this: (working up an example...)
(let [rr (comp reverse range)]
(loop [a (rr 3)
b (rr 3)
c (rr 3)
acc []]
(cond
(empty? a) acc
(empty? b) (recur (rest a)
(rr (first a))
(rr (first a)) acc)
(empty? c) (recur a (rest b)
(rr (first b)) acc)
:else (recur a b (rest c)
(conj acc (apply str (map first [a b c])))))))
@cfleming: (not my cleanest code, but it gets my idea across. It effectively looks like one loop, even though the seq
s a
b
c
are all getting looped over)
@cfleming: so you start with 3 seqs, a is the highest level, followed by b then c. When c is empty, it fills up again from b. Same with b from a. When a is empty, you know that there's nothing left to process. The last line of code with conj ...
is where you do the work using the relevant parts of a
b
c
.
@josh.freckleton: Thanks - that does actually look pretty clean. I’ll give that a go, thanks!
if I have a java object that implements an interface (`WebDriver`) and a clojure protocol (`IDriver`) that is extended over that interface (`(extend-type WebDriver IDriver …)`) should the protocol work over any java objects that also implement the interface?
@cfleming: is reductions
helpful?
hello, someone know why when i am try to insert values into postgres like this: (sql/insert! db :users {:email (:email user) :password (:pass user) :username (:username user)}) in db i had field with free spaces? most of columns 100 symbols length according db scheme. but when i try to compare same values from db and (noir.util.crypt/encrypt ourpass) its different, because i think problem if free spaces? db gives me pass like this "somehashingpass " - my pass to compare is "somehashingpass" i use [org.clojure/java.jdbc "0.6.1"] and driver [org.postgresql/postgresql "9.4.1208.jre7"]
Hi, I need to use rdf4j repository with lucene index. These all things are provided but it seems it is not thread safety somewhere in deep on the lucene side. So I should assume the pessimistic variant that thread safety is not provided at all. I would like to wrap the repository in one thread and communicate with the rest through the channel. Multiple threads will do input file reading and populate the channel. What do you think about that. Is it possible to implement it in a quick-and-dirty solution?
@agi_underground: is the password column defined as CHAR or as VARCHAR?
That’s why then. CHAR always pads out to the full width of the column, use VARCHAR to keep only the actual length of the string
(I’m hoping that’s right anyway, I haven’t done postgres for a while, but I think that’s standard SQL)
@manutter51: yes, thank you, it`s work!
:thumbsup:
hi there! are there any opinions on the new "Professional Clojure" book yet? My google searches came out empty :(
I find myself doing quite a bit of this: (remove nil? (map :some-key heterogeneous-collection))
Wondering if it's a code smell
What do folk use/suggest in Clojure (or ClojureScript) for mesh manipulation (remeshing, extruding, etc ...) ?
(I do not need the rendering part, only the processing of it)
oh maybe I found a good candidate: https://github.com/thi-ng/geom
I'm curious to know the explanation behind this:
user=> (clojure.set/difference #{"foo" "bar"} ["bar" "foo"])
#{}
user=> (clojure.set/difference #{"foo" "bar"} ["bar" "foo" "quux"])
#{"bar" "foo"}
What I understand is that clojure.set/difference
expects sets for all of its arguments.
That’s just what happens as a result of the implementation (which expects sets) - you can read the impl to understand why. The result you’re seeing won’t make sense as it violates assumptions in the impl.
https://github.com/clojure/clojure/blob/b5d0e84f92038449312bea4c31dcdedd499e28b8/src/clj/clojure/set.clj#L48 if you’re interested