Don't know what you mean about "swapping", but here's a solution that 
generalizes to a tree of any finite depth, where each node is either a leaf 
element or a seqable (say, a vector) of any length:

(defn coord-of

  ([elems target]
   (coord-of elems target []))

  ([elems target indexes]
   (first (keep-indexed
            (fn [i x]
              (cond
                (= x target)  (conj indexes i)
                (seqable? x)  (coord-of x target (conj indexes i))))
            elems))))

Then, for example,

cljs.user=> (coord-of [[] 11 [1 2 3] [4 5 6]] 5)
[3 1]
cljs.user=> (coord-of [[] 11 [1 2 3] [4 5 6]] 55)
nil

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to