Fork me on GitHub

oh well, for the size of my trees (less than 100 nodes) it looks like a linear search will be fast enough:

(def data
   {:span [21 22] :id 13}
   {:span [10 20] :id 12}
   {:span [17 19] :id 11}
   {:span [16 17] :id 10}
   {:span [15 17] :id 9}
   {:span [13 14] :id 8}
   {:span [11 12] :id 7}
   {:span [8 11] :id 6}
   {:span [7 9] :id 5}
   {:span [6 9] :id 4}
   {:span [6 8] :id 3}
   {:span [3 5] :id 2}
   {:span [0 2] :id 1}])

(defn find-intervals [data, n]
    (fn [{span :span}]
          (>= n (first span))
          (< n (second span))))


  (dotimes [n 20000000]
    find-intervals data (mod n 22)))
"Elapsed time: 480.723187 msecs"


is there a merge for vectors?


You could do something like (vec (concat [0 1 2 3] [4 5 6 7])) ;;=> [0 1 2 3 4 5 6 7]

Chris O’Donnell04:07:43

or (reduce conj [0 1 2 3] [4 5 6 7])


@roberto: (into [0 1 2] [9 8]) is probably best, it'll use transients.

Chris O’Donnell05:07:50

into is really great. I should remember to use it more.

Alex Miller (Clojure team)05:07:46

tastes even better with transducers

Alex Miller (Clojure team)05:07:57

(into [] cat [[0 1 2 3] [4 5 6 7]]) ;;=> [0 1 2 3 4 5 6 7]

Chris O’Donnell05:07:58

And the transducer solution works with arbitrarily many vectors, though it doesn't use transients. Nice!

Chris O’Donnell05:07:15

it does? that's awesome

Alex Miller (Clojure team)05:07:31

it will collect into the vector at the front (made transient)

Alex Miller (Clojure team)05:07:58

it’s way more efficient than the vec concat version above

Chris O’Donnell05:07:12

it uses transients because into uses transients?

Alex Miller (Clojure team)05:07:25

plus you get to have your cat around

Alex Miller (Clojure team)05:07:31

so it’s internet friendly

Drew Verlee11:07:37

what does “bouncing the repl” mean?


@drewverlee: shutting it down and starting it back up, I believe.

Drew Verlee13:07:02

@d-side: thanks that makes sense in the context i was reading.


This is what I get for not paying attention to transducers. [looks haughty]


can one use transients with a sorted-map? I get errors but nowhere in the documentation does it say that transients can't be used with a sorted-map


(def tmap (transient sorted-map))
CompilerException java.lang.ClassCastException: clojure.core$sorted_map cannot be cast to clojure.lang.IEditableCollection, compiling:(form-init206135609334303987.clj:1:11) 


It looks like the core sorted maps don't implement the right protocol, but there's which demonstrates using them with transient.


Though in your code, note you'd need (transient (sorted-map)) even if it did work.


what would be a good way to write this so recur is the last form?


nvm, i just rewrote it without tail optimization


that can wait until i’ve a working version


Hi. Have a cljs question regarding foreign-libs. I have this in my dev cljs build:

:foreign-libs    [{:file     "resources/browserified/foo.js"
                   :provides [""]}
And in my cljs file I have (:require []). This works, I get access to the stuff in foo.js from the browser console.


Problem is, when I try to load that same cljs file in the figwheel REPL I get java.lang.IllegalArgumentException: Namespace does not exist


What could I be doing wrong?


You may try asking in #C1A38UB5X, though I'm not sure how active it is


Seems to be the same issue


@polymeris: Best channel to ask is #C0B22RS2Y, it's pretty active.


Ok. I'll try that. Thanks, @shaun-mahood & @dg