On Thu, Oct 24, 2013 at 5:32 PM, Kelker Ryan <[email protected]> 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 are on loop/recur and if-let: How would if-let version of my
function common divisors look like? Would I benefit from it in any way?
(defn cds [x y]
(loop [a x
b y
result []]
(if (= 0 (rem a b))
(conj result b)
(recur b (rem a b) (conj result (int (/ a b)))))))
--
Regards
Bartosz Kaliszuk
bartosz(dot)kaliszuk(at)gmail(dot)com
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.