code-reviews

2019-08-25T17:43:08.058100Z

hi guys, I'm converting a function that uses a ref to a loop/recur, but this function isn't amenable to tail recursion because it has multiple if's that may change the result... any quick shots?

(defn point-query 
  ([tree point] 
   (let [results (ref [])
     (point-query tree (get-root tree) point results)]
     @results))

  ([tree node point results]
   (if (not= node (get-sentinel tree))
     (let [interval (get-interval node)]
       (if (<= point (get-max node))
	       (point-query tree (get-left node) point results))
       (if (interval-tree.interval/contains interval point)
         (alter results conj (get-interval node) (get-value node)))
       (if (>= point (low interval))
	     (point-query tree (get-right node) point results))))
   results))

2019-08-25T17:43:38.058500Z

those 3 ifs can happen in the same fn call