Hi All,
I am just learning clojure and I've written a function to split a list (see 
docstring for details). I was wondering if any of you experienced hands 
could take a look at it and comment. I've never used lisp or a functional 
language before so I was wondering if I was doing it right or if there is a 
better way. Anyway here is the function:

(defn split-zero 
  "Split a collection at its zero values into a list of lists.
   Multiple zeros are treated as one.
   The order of elements in each inner list is maintained but
   the order of inner lists in the result may be changed.
   e.g. (split-zero '(1 2 3 0 4 5 6 0 7 8 9))
   -> ((7 8 9) (4 5 6) (1 2 3))"
  [ls] ((fn [ls wip ans] 
        (if (empty? ls)
          (if (empty? wip) ans (conj ans (list* wip)))
          (if (zero? (first ls))
            (if (empty? wip)
              (recur (next ls) [] ans)
              (recur (next ls) [] (conj ans (list* wip))))
            (recur (next ls) (conj wip (first ls)) ans)))) ls [] nil))

Thanks,
Peter

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