On Wed, Apr 21, 2010 at 8:46 AM, Sean Devlin <[email protected]> wrote:
> You're right about changing the docstring to read ""sequence"
>
> I think the lazy-cat version looses the ability to rotate in reverse,
> which I've come to love from Ruby.  Also, I have found use cases where
> I want to rotate a period longer than the sequence length.
>
> Thanks for the feedback, though.
> Sean

The use of concatenation as opposed to cycle does not affect the
ability to rotate in reverse or more than the sequence length provided
you use mod to get the number in range first:

(defn rotate [n s]
  (let [shift (mod n (count s))]
    (concat (drop shift s)
            (take shift s))))

[could use lazy-cat instead of concat, but I doubt it's worthwhile here]

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

Reply via email to