Fork me on GitHub
#clojure
<
2016-06-25
>
cfleming02:06:19

@danielcompton: I don’t think so, since it’s still creating a seq.

danielcompton02:06:49

@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-L327

vandr0iy03:06:35

Hi clojurians! is there a way to invert the order of threading inside a ->> macro?

vandr0iy03:06:29

say, 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

luxbock10:06:11

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?

val_waeselynck11:06:07

@luxbock: yeah I would not recommeng doing that

val_waeselynck11:06:15

Although the Monger library does it

val_waeselynck11:06:32

can't you use a sorted map?

luxbock11:06:31

@val_waeselynck: yes I could, but I'm serializing this data as EDN and sorted-maps don't work so well with that

bcbradley11:06:22

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

bcbradley11:06:35

here is my implementation:

bcbradley11:06:36

(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))

bcbradley11:06:21

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

luxbock11:06:17

@bcbradley: recur only works for tail-recursion

bcbradley11:06:20

wouldn't this be tail recursion without the (every? ...)

luxbock11:06:50

without it yes 🙂

val_waeselynck11:06:07

@bcbradley: tail recursion isn't really compatible with dividing the problem then combining the results

bcbradley11:06:17

are you certain?

luxbock11:06:19

(nil? (not-empty s)) can be (empty? s)

bcbradley11:06:33

thanks for that lux

bcbradley11:06:56

i'm not really trying to "combine" results in a merge fashion

bcbradley11:06:22

as soon as i can determine that the substructure is not met by the provided collection, i can return false

bcbradley11:06:44

i suppose (not (some (not ... could replace (every?

bcbradley11:06:53

but that doesn't fix the recur problem

bcbradley11:06:33

i'm open to reworking the whole function if you can come up with a better way to do it

bcbradley11:06:58

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

bcbradley11:06:07

i don't want to use a trampoline unless i have to

bronsa12:06:14

@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

bronsa12:06:14

arraymaps and sorted-maps have different kinds of "ordering". arraymaps guarantee insertion order, sorted-maps guarantee ordering based on properties of the keys

romb22:06:33

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

akiva22:06:50

What are you expecting it to do?

hiredman22:06:42

var is a special form

hiredman22:06:53

(var x) is the same as #'x

gfredericks22:06:55

(var var) is the same as #'var

romb22:06:32

I'm wondering how Clojure resolves that

seylerius22:06:45

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?

bpicolo22:06:31

sounds like infinite recursion

seylerius22:06:08

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.

seylerius22:06:06

@bpicolo: A (the dispatch function) needs to be called by some of the individual handlers because they may contain further nodes of the tree.

seylerius22:06:05

The recursion is as infinite as an Emacs org-mode file.

seylerius23:06:56

Maybe let-fn

seylerius23:06:52

Ah. declare will do the job.