Fork me on GitHub

any ideas about properly leading incanter dependencies into namespace?

Drew Verlee01:11:18

i’m curious how someone might find the intersections between a vector of points: input: [[1 3] [2 4] [5 6]] output: [[1 4] [5 6]] I started off trying to do this with a reduce, but im not sure how to handle the case when the return value is a merged list.


excuse my ignorance, but how do you find an intersection between some points? don't you need, like, vectors, or straight lines?

Drew Verlee10:11:28

Right, I should have said lines as represented by 2 points.


but still your input is not clear, you need 4 points to define two lines


so, like this? input: [[[1 2] [5 6]] [[1 3] [7 8]]] output: [x y]


section: Given two points on each line


I will continue my server questions. I have clojure server with clojurescript front and I have used cljs-ajax with JSON to transfer data between them. In server side I have used wrap-restful-format to serialize data structures to JSON but it seems really picky on what kind of structure I give it to it


So is there better library for handling JSON server side? Or maybe better Clojure specific way to transfer data between server and front?


@neurogoo there is transit: and several libraries with support for it, I think cljs-ajax has it as default even. I use this middleware with ring: and it worked out so far


Thanks @sveri I will try that

Drew Verlee16:11:22


input: [[1 3] [2 4] [5 6]]
output: [[1 4] [5 6]]
the input would be 3 lines. the output would be the merged lines merge((1,3), (2,4)) => (1,4) and in the case when they dont intersect, then just the original lines/inputs merge((1,4), (5,6)) => [(1,4), (5,6)]. That second aspect is what causes it hard to see how i can use reduce.

Drew Verlee16:11:17

maybe the confusion is because their is only 1 dimension with these “points” more specifically im trying to find if two “times” overlap so the input would be more like (sunday_at_5, sunday_at_7), (sunday_at_4, sunday_at_6)


[1 3] and [2 4] are points, not lines - unless you intend them as vectors starting from origin, but in that case they do not intersect


if I understand you correctly

Drew Verlee16:11:15

@vandr0iy Line1 = 1-to-3 Line2 = 2-to-4 There is only one dimension. so instead of (x,y) this is just (x,x). Does that make sense


ooh... so you're trying to merge some ranges!

Drew Verlee16:11:22

right, so maybe the right word here is range instead of line.


The right term should be "interval", mathematically speaking

Drew Verlee16:11:54

@rauh thanks, i forgot the importance of finding the right word before searching for an answer. Using interval i get a lot better search results.


yes, you're looking for merging intervals, you should easily find proper algorithms



(defn merge-intervals [vs]
  (let [sorted (sort (map (comp vec sort) vs))
        f (fn [res el]
            (let [[a b] (first res)
                  [na nb] el]
              (if (< na b)
                (cons [a nb] (rest res))
                (cons el res))))]
    (reverse (reduce f [(first sorted)] (rest sorted)))))


I think it can be more optimal


A simplification for this:

(vec (flatten (vector [1 2 3] [2 4 5]))) ; returns [1 2 3 2 4 5]
eludes me. Can anyone think of one?


how about concat?


OK. May have it. `(vec (concat


yeah i sut spotted it


nice : )

Drew Verlee22:11:45

@tsulej thanks! Ill give this a look. I see reduce in their which peeks my curiosity as i banged my head trying to make that fit.


@gamecubate: into often surprises: (into [1 2 3] [2 4 5])


Ah yes. Thanks @mfikes. Humbling that, having finished writing a pretty big project in cljs&reagent front-end + node.js backend project, I’m still weak on basic stuff.