Oh that is confusing!
nth indexes from 0 where-as take-nth indexes from 1.
The doc string could be considered misleading, as it says that take-
nth makes a sequence of "nth" items, but clearly it does not:
clojure.core/take-nth
([n coll])
  Returns a lazy seq of every nth item in coll.

user=> (take-nth 1 [1 2 3 4])
(1 2 3 4)
user=> (nth [1 2 3 4] 1)
2



On Oct 28, 7:36 am, alxtoth <alexandru.t...@gmail.com> wrote:
> Hi,
>
> Started tinkering with Clojure, and wonderring why (take-nth 0 (range
> 10)) returns an infinite sequence ..  Is this really the expected
> behaviour?
>
> ;
> ;code bellow is public domain
> ;
> (defn take-nth-proposal
>   "Returns a lazy seq of every nth item in coll . Or nil if n less
> than 1."
>   [n coll]
>     (if (< n 1)
>      nil
>      (lazy-seq
>       (when-let [s (seq coll)]
>         (cons (first s) (take-nth n (drop n s)))))))
>
> -Cheers, Alex
--~--~---------~--~----~------------~-------~--~----~
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