Re: First function

2010-10-26 Thread Brody Berg
Thanks for all the excellent, concise advice! For code and idiomatic improvements, from these messages I have the following - For order 1 access use vector - Use subvectors for efficient partitioning - Case/compare is concise, powerful and readable - Use seq idiom to proceed or return

Re: First function

2010-10-21 Thread Jürgen Hötzel
2010/10/21 Brody Berg : > (defn binary-search >    "Search sorted list for target using binary search technique" Binary search is only useful on indexed data types like Clojure Vectors. >    ([m_list target] >        (if (empty? m_list) >            false >            (binary-search m_list 0 (- (

Re: First function

2010-10-21 Thread Alan
To expand on this: 1. It's better to use when (or when-not) if one branch of your if is just a false value. E.g. you could replace (if (empty? x) false (whatever)) with (when-not (empty? x)). However... 2. Don't use empty? if you can help it! The idiomatic way to test whether a collection has any

Re: First function

2010-10-21 Thread songoku
You should close the parenthesis all in one line: (defn binary-search "Search sorted list for target using binary search technique" ([m_list target] (if (empty? m_list) false (binary-search m_list 0 (- (count m_list) 1) target))) ([m_list m_left m_right

Re: First function

2010-10-21 Thread Michael Gardner
On Oct 21, 2010, at 3:28 AM, Brody Berg wrote: >(if (== (nth m_list m_left) target) Forgot to mention: you should use = instead of == unless you're sure you will only ever get numeric arguments *and* profiling tells you that = is a performance bottleneck. -- You received this

Re: First function

2010-10-21 Thread Michael Gardner
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