I’m trying this: however, It explodes on me because apparently it isn’t valid syntax that the more left binding form refers to the right binding form. Now, I can do this by replacing the right-side with a map statement; but is there a syntactic trick for doing this purely in the for statement?
Pseudo-code: Given a collection of collections, for each 1st-level collection, partition it; then for each partition, do a calculation based on the two elements of that partition.
(let [nested-data [[1 "bat" 2 "frog"] [1 "puppy" 2 "kitty"]] ]
(for [[[size source] [_ target]]
(partition 2 1 branch)
branch nested-data]
(str "The " source " takes " size " steps toward the " target)))
;; desired output:
;; ("The bat takes 1 steps toward the frog" "The puppy takes 1 steps toward the kitty")
Talking this through with a colleague we found that you CAN refer to other things in the for binding sequence – unexpected to me was that, although right-more represents the outer loops, references are available in a left-first manner. In other words, for [a acoll b (map first a)] works, because b can refer to the a on its left. But it seems that the “faster” inner cycle (lefter) CANNOT refer to the slower outer-cycle (righter).
Well, sanity-checking with my faith in the clojure devs paid off. RIGHTER is faster, so it DOES make sense that it can refer to lefter definitions. I’m glad the clojure devs are so smart.