Binary search algorithm in Clojure I'm absolutely new to Clojure (started learning it yesterday). After I went through some tutorials and checked out the basics I implemented the following Binary search algorithm:

(defn log-search
    [elements, elem-to-find]
        (loop [left 0
            right (- (count elements) 1)]
          (when (&lt;= left right)
          (def m (int (Math/floor (/ (+ left right) 2))))
          (def actual (nth elements m))
              (cond
                  (= actual elem-to-find) m
                  (&lt; actual elem-to-find) (recur (+ m 1) right)
                  (&gt; actual elem-to-find) (recur left (- m 1))))))


The followings are intentional in the implementation:


returning nil on empty sequence 
I return nil if the element is not present  
I do not care if (+ left right) overflows on very big sequence (I'm focusing only on the language features)


My questions:


Is there any Clojure (or funcional programming) antipattern in the
code? 
What would be a more functional (or Clojure) approach?


Any other suggestions are more than welcomed.

Thank you.
Your implementation is pretty similar to this one: https://programming-pages.com/2012/01/31/binary-search-in-clojure/

I think the overall algorithm is OK.
You should avoid using def inside function - that should be used only for global top-level vars -> use let instead.
Also, the code formatting is incorrect - use 2 spaces and proper indentation:

(defn log-search
  [elements elem-to-find]
  (loop [left 0
         right (dec (count elements))]
    (when (&lt;= left right)
      (let [m (int (Math/floor (/ (+ left right) 2)))
            actual (nth elements m)]
        (cond
          (= actual elem-to-find) m
          (&lt; actual elem-to-find) (recur (+ m 1) right)
          (&gt; actual elem-to-find) (recur left (- m 1)))))))