While it would be possible to support it, I don't think that it makes sense
for maps (or sets).

While first and next need to be supported to make maps and sets sequable, I
don't think that conceptually the elements are ordered.

Cheers,

Chris

On 12 June 2012 11:03, Yoshinori Kohyama <yykohy...@gmail.com> wrote:

> Hello forum,
>
> Given
>
> (def m (sorted-map 1 :a 2 :b 3 :c 4 :d 5 :e))
>
> ,
>
> (nth m 0)
>
> throws 'UnsupportedOperationException nth', while
>
> (first m)     ; -> [1 :a]
> (next m)      ; -> ([2 :b] [3 :c] [4 :d] [5 :e])
> (nthnext m 1) ; -> ([2 :b] [3 :c] [4 :d] [5 :e])
> .
>
> How do you think about nth accepts maps
>
> (defn my-nth [coll index]
>   (loop [n index xs (seq coll)]
>     (if-let [x (first xs)]
>
>       (if (zero? n) x (recur (dec n) (next xs))))))
>
> (my-nth m 0) ; -> [1 :a]
>
> like the implementation of nthnext?
>
> Of cource, this should be used for collections only which don't supported
> nth directly, I think.
>
> A form
>
> (let [[a b c & d :as e] [1 2 3 4 5]]
>   [a b c d e])
>
> returns
>
> [1 2 3 (4 5) [1 2 3 4 5]]
> , but
>
> (let [[a b c & d :as e] (sorted-map 1 :a 2 :b 3 :c 4 :d 5 :e)]
>   [a b c d e])
> throws 'UnsupportedOperationException nth'.
>
> What do you think if it returned
>
>   [[1 :a] [2 :b] [3 :c] {4 :d 5 :e} {1 :a 2 :b 3 :c 4 :d 5 :e}]
>
> .
>
>
> Or isn't it good that you can write operations for a map like
>
> (loop [[[k v :as x] & xs] m acc '()]
>   (if x
>       (recur xs (cons acc (some-operation-for k v)))
>       acc))
>
> ?
>
>
> Please let me hear opinions.
>
>
> Regards,
>
> Yoshinori Kohyama
>
>  --
> 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

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