On Mon, Aug 8, 2011 at 2:29 PM, MarisO <maris.orbid...@gmail.com> wrote:
> Do you know of any trick to reverse a sequence without reverse or > rseq ? > > I wrote it like this: > > ((fn rev > ([s] (rev '() s)) > ([r s] (if (seq s) (rev (cons (first s) r) (rest s)) r )) ) > '[1 2 3 5] ) > > > https://gist.github.com/1132357 > > > I wonder if it can be written more shortly. > Another way to do it would be to follow the example of shuffle and defer to Java collections: (defn reverse "Return coll, reversed" [coll] (let [al (java.util.ArrayList. coll)] (java.util.Collections/reverse al) (clojure.lang.RT/vector (.toArray al)))) -- 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