> > > (defn chunk "Lazily break s into chunks of length n (or less, for the > > > final chunk)." > > > [n s] > > > (when (seq s) > > > (lazy-cons (take n s) > > > (chunk n (drop n s))))) > > > Should that "seq" be "seq?". If not, why not?
On Jan 13, 7:17 pm, "Nick Vogel" <voge...@gmail.com> wrote: > seq returns nil when a collection has no items. According to the > documentation for empty?, empty? is the same as (not (seq coll)) so you > should use seq for expressing the opposite of empty? According to my experiment, the code above works equally well whether 'seq or 'seq? is used. Intuitively (i.e. without actually knowing :) seq? is more efficient because it returns a boolean, not a newly- allocated sequence. So, either: 1. My experiment was wrong, and seq? is not a valid stand-in for seq in the above code. 2. My intuition is wrong, and 'seq? is not more efficient than 'seq. 3. 'seq and 'seq? are equally valid, but 'seq is preferred because of the definition of 'empty? Or something else. Which is it? Thanks, Gavin --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---