Re: Need help with recursion!

2013-10-24 Thread Kelker Ryan
The code you pasted doesn't actually find the common divisor of two numbers.  user> (cds 100 200)[0 100] Here's my code using loop/recur (defn cds [x y]  (loop [i (->> (min x y) inc (range 1)) ret []]    (if-let [n (first i)]  (if-not (= 0 (rem x n) (rem y n))    (recur (rest i) ret

Re: Need help with recursion!

2013-10-24 Thread Bartosz Kaliszuk
On Thu, Oct 24, 2013 at 5:32 PM, Kelker Ryan wrote: > Try this. > > (defn my-filter [pred? coll] > (loop [c coll > ret (empty c)] > (if-let [x (first c)] > (if (pred? x) > (recur (rest c) (lazy-cat ret [x])) > (recur (rest c) ret)) > ret))) > While we a

Re: Need help with recursion!

2013-10-24 Thread Kelker Ryan
Try this. (defn my-filter [pred? coll] (loop [c coll ret (empty c)] (if-let [x (first c)] (if (pred? x) (recur (rest c) (lazy-cat ret [x])) (recur (rest c) ret)) ret))) 24.10.2013, 23:58, "Wilson" : >  I am supposed to make my own filter function witho

Re: Need help with recursion!

2013-10-24 Thread Wilson
Thank you both for your help! That was so quick! Jeb's solution worked like a charm, and now I can finally advance to the next exercise. -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.co

Re: Need help with recursion!

2013-10-24 Thread Bartosz Kaliszuk
Hi Wilson, As I'm learning clojure myself, I won't help you with code, but with algo:P 1. you are missing the pred? in my-filter call 2. you are missing the else clause for the if statemant handling situation when first element on the list does not meet the pred? criteria. I hope this helps. Rega

Re: Need help with recursion!

2013-10-24 Thread Jeb Beich
Tweaked slightly... (defn my-filter [pred? a-seq] (if (empty? a-seq) a-seq (if (pred? (first a-seq)) (cons (first a-seq) (my-filter pred? (rest a-seq))) (my-filter pred? (rest a-seq) On Thu, Oct 24, 2013 at 9:51 AM, Wilson wrote: > I am supposed to make my own filter