Hi Stefan,
I am overwhelmed by the 'freedom of choice' Clojure gives you, too. In that 
respect it's more like ruby than python.
Nevertheless, I think if you can come up with an algorithm using the built in 
functions over sequences like map, reduce, filter, etc. 
you should do so. 
Either way, it doesn't really matter which way you do it, just do it right and 
then refine as you go (and gain more experience). 
Just be aware that you have to explicitly loop-recur for tail recursive 
processes, recursive processes might blow up your call stack pretty quickly.
 
So that would cover 1)
For 2)
I can think of a straight forward tail-recursive process to do what you want:

 (defn drop-by [f coll]
            (loop [coll coll]
               (let [x (first coll)
                    y (second coll)]
                    (if (and x y (= (f x) (f y)))
                        (recur (rest coll))
                        (rest coll)))))

Maybe someone on this list can think of an implementation in terms of sequence 
functions. 

Cheers
Andreas
P.s. The most powerful tool that comes with Clojure is this community. Use it!

On 03/04/2011, at 5:23 PM, Stefan Rohlfing wrote:

> @ Ken, Andreas
> 
> Thank you for your nice implementations!
> 
> As far as I can see, there are two main methods of comparing adjacent items 
> of a list:
> 
> 1) Take the first item of a coll. Compare the remaining items with an offset 
> of 1:
> (map f coll (rest coll))
> ;; apply some sort of filter
> 
> 2) Take the first and the second item of a coll. Test if both items exists 
> and then compare: 
> (let [x (first coll), y (second coll)]
>    (and x y (= (f x) (f y)))) 
> 
> The first method works for take-by, but not for drop-while (or so I think).
> 
> Using the second method take-by can be changed into drop-by by only changing 
> the last two lines:
> 
> (defn drop-by2 [f coll]
>   (lazy-seq
>     (when-let [s (seq coll)]
>       (let [x (first s)
>             y (second s)]
>         (if (and x y (= (f x) (f y)))
>           (drop 2 s)
>           (drop 1 s))))))
> 
> 
> I am curious to know if one of these methods is the preferred way of doing a 
> comparison in Clojure (aka Python's one way of doing things). The sheer 
> number of possible solutions to the same problem sometimes overwhelms me a 
> bit, so that I'm looking for some orientation ;-) 
> 
> Best regards,
> 
> Stefan
> 
> 
> -- 
> 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

--
"Test-driven Dentistry (TDD!) - Not everything should be test driven"
- Michael Fogus
-- 
**********************************************************
Andreas Koestler, Software Engineer
Leica Geosystems Pty Ltd
270 Gladstone Road, Dutton Park QLD 4102
Main: +61 7 3891 9772     Direct: +61 7 3117 8808
Fax: +61 7 3891 9336
Email: andreas.koest...@leica-geosystems.com

************www.leica-geosystems.com*************

when it has to be right, Leica Geosystems

Please  consider the environment before printing this email.

-- 
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