On Oct 21, 2010, at 3:28 AM, Brody Berg wrote:

>        (if (empty? m_list)
>            false
>            (binary-search m_list 0 (- (count m_list) 1) target))

Assuming that returning nil is OK in case of the target not being present, you 
can replace this with (when (seq m_list) (binary-search ...)).

>                (if (== (nth m_list m_left) target)
>                    (nth m_list m_left)
>                    false

Can similarly replace with (when (== (nth m_list m_left) target) target). But 
why are you returning the target value on success? Presumably the caller knows 
what that value is, and it makes your function awkward to use if target is 
false or nil. Why not return either the target's index, or just 'true' if you 
don't need that?

Also, can you assume m_list is a vector, or if not, make it into one in your 
helper body? That would let you write (m-list n) instead of (nth m-list n), and 
would guarantee constant-time performance when you do it.

> (- middle 1)
> (+ middle 1)

Can replace with (dec middle) and (inc middle), respectively.

Lastly, as a matter of style: Lisp users generally hate trailing parentheses. 
It's extremely common to simply collapse them onto the previous line. Your 
editor should be able to do the grunt-work of helping you balance them, and 
they pretty much disappear after a while.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to