Hi all,

Thank you for commenting, Chris and Meikel.

In my Clojure 1.3.0 REPL,
  (def sm (sorted-map 0 {:name "Alice"} 1 {:name "Bob"} 2 {:name 
"Charlie"}))
  (loop [c sm acc []]
    (if-let [[k v] (first c)]
      (recur (next c) (conj acc (assoc v :id k)))
      acc))
returns
  [{:name "Alice", :id 0} {:name "Bob", :id 1} {:name "Charlie", :id 2}]
. And
  (nthnext sm 1)
returns
  ([1 {:name "Bob"}] [2 {:name "Charlie"}])
.
'first', 'next' and 'nthnext' look to accept a map for me.
Do I misunderstand something?

I only want to write an example above like:
  (loop [[k v :as x] & xs] sm acc []]
    (if c (recur xs (conj acc (assoc v :id k))) acc))
.
And it can be done only if 'nth' accepts a map, by implementing 'nth' using 
'seq', 'first', 'next', 'loop' and 'recur' like 'nthnext' or 'my-nth' in 
the first post.
https://github.com/clojure/clojure/blob/d0c380d9809fd242bec688c7134e900f0bbedcac/src/clj/clojure/core.clj#L2747

Note that the example above is done without a loop, I know, and  I forced 
to use a loop for a demonstrative purpose.

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

Reply via email to