(not sure where my reply to Chouser et al. went, but basically I said
that I was writing a macro and I might be overdoing it.  I was right!)

Here's what I was trying to accomplish, but in functions, not macros:


(defn slice
  "Returns a lazy sequence composed of every nth item of
   coll, starting from offset."
  [n offset coll]
  (if (= offset 0)
    (take-nth n coll)
    (take-nth n (drop offset coll))))

(let [take-helper
      (fn [n slices coll]
        (apply interleave (map #(slice n % coll) slices)))]
  (defn take-slices
    "Returns a lazy sequence of items from coll.  Items are
    rearranged according to non-negative indexes contained
    in collection slices, in blocks of size n (which defaults
    to (+ 1 (apply max slices)).

    Ex: (take-slices [3 2 1] (range 14)) -> (3 2 1 7 6 5 11 10 9)
        (take-slices 5 [2 0] (range 20)) -> (2 0 7 5 12 10 17 15)"
    ([slices coll]
       (take-helper (+ 1 (apply max slices)) slices coll))
    ([n slices coll]
       (take-helper n slices coll))))


Thanks again to everyone who replied!
Mike

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