On Wed, Dec 17, 2008 at 1:55 PM, Rich Hickey <richhic...@gmail.com> wrote: > > > > On Dec 17, 3:43 am, "Remco van 't Veer" <rwvtv...@gmail.com> wrote: >> Hi all, >> >> First off, thanks for clojure! I've been playing with it for a couple >> days now and love it! >> >> Doing ruby in my day job, I've found some quirks I don't really >> understand. Most of them are obviously me being new to clojure and a >> lisp "beginner". But the following keeps bugging me: >> >> user> (partition 2 '(1 2 3 4 5)) >> ((1 2) (3 4)) >> >> Why is partition swallowing the remaining element of the given >> sequence? I expected partition to return ((1 2) (3 4) (5)). The >> current implementation of partition will ensure code expecting groups >> of a given size will not break when given an unevenly distributed >> sequence. But IMO that code is responsible for how partition is >> called and should sanitize if needed. The current implementation >> might even obscure one-off errors and silently drop data. >> >> Since the current implementation is slightly more complex than the >> more lenient version I expected, there's probably a good reason why >> it's implemented as it is now. Can anybody enlighten me? >> > > Well, if you were doing Mathematica in your day job you might find it > unsurprising: > > http://documents.wolfram.com/mathematica/functions/Partition > > I don't think cleaning up the end is very efficient. And what does > (partition 3 ...) say to the reader of the code? If it only says > "you'll get sets of 3, or maybe less" that's not saying much. The > current logic pushes the onus on the producer of the data, where it > belongs, rather then the consumer. > > Not that there couldn't be a variant that made weaker promises. > > Rich
Makes sense, I am confusing partition with ruby's each_slice. Slice is a nice name for such a variant. Thanks! Remco --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---