This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-06-25
Channels
- # beginners (21)
- # boot (37)
- # cljsjs (1)
- # cljsrn (1)
- # clojure (48)
- # clojure-greece (3)
- # clojure-poland (1)
- # clojure-quebec (4)
- # clojure-spec (40)
- # clojure-uk (1)
- # clojurescript (113)
- # cursive (13)
- # events (3)
- # hoplon (183)
- # jobs (5)
- # off-topic (2)
- # onyx (49)
- # planck (35)
- # re-frame (8)
- # reagent (2)
- # sim-testing (1)
- # specter (4)
- # spirituality-ethics (2)
- # untangled (1)
- # vim (2)
- # yada (1)
@danielcompton: I don’t think so, since it’s still creating a seq.
@danburton: dirty Clojure trick
user=> (contains? [:a :b :c] :b)
false
user=> (.contains [:a :b :c] :b)
true
https://github.com/clojure/clojure/blob/clojure-1.8.0/src/jvm/clojure/lang/APersistentVector.java#L322-L327say, at a certain step I need the result of the previous to be taken as the first argument, not as the last. I often use #(function % var1 var2) in order to accomplish this, but I believe there has to be a more idiomatic way to do it
@vandr0iy: take a look at as->
thanks @codonnell
would relying on the fact that PersistentArrayMap
retains the order of its keys be a really bad idea if I know my map will only ever contain 4 entries?
@luxbock: yeah I would not recommeng doing that
Although the Monger library does it
can't you use a sorted map?
@val_waeselynck: yes I could, but I'm serializing this data as EDN and sorted-maps don't work so well with that
I need to create a utility function to verify that a map contains a substructure, for example {:a "boo" :b{:d "hoo" :e "wam"} :c "bulance"} would have a substructures defined as {}, {:a #{} :c #{}}, {:b #{:d :e}}, among others
(defn has-substructure? [i s] (cond (nil? (not-empty s)) true (nil? (not-empty i)) false (map? s) (every? #(and (contains? i (key %)) (has-substructure? (get i (key %)) (val %))) s) (set? s) (every? #(contains? i %) s) :else false))
I am trying to figure out how to use the recur keyword instead, but it won't work as is because the macro #(...) expands to (fn ...) which intercepts the recur
@bcbradley: recur
only works for tail-recursion
@bcbradley: tail recursion isn't really compatible with dividing the problem then combining the results
as soon as i can determine that the substructure is not met by the provided collection, i can return false
i'm open to reworking the whole function if you can come up with a better way to do it
I'll give it a look, but i know what tail recursion is. I'm just trying to figure out how to make my algorithm tail recursive
@luxbock: not a bad idea if you construct the map via array-map
and you're sure you're not going to conj
/`dissoc` from it. it's documented behaviour
arraymaps and sorted-maps have different kinds of "ordering". arraymaps guarantee insertion order, sorted-maps guarantee ordering based on properties of the keys
Hi can someone help me understand what's going on here. user=> (def var 42) #'user/var user=> (prn var (var var)) 42 #'user/var
(var var)
is the same as #'var
If only func-a needs to call func-b, func-c, and func-d, but func-c and func-d also need to call func-a, how would you organize that?
Selective dispatch. Based on contents of supplied map, A calls one of B, C, or D on the map. C and D maps may contain further maps that need to be dispatched on, thus handing back to A. Tree-structure. Has a bottom.