Hi,

2009/12/2 Konrad KuĊ‚akowski (kony) <kulakow...@gmail.com>

> Recently I need something which works as "inverse of interleave"
>
> I did something like that:
>
> (defn unravel [expr-list]
>        (loop [flist () slist () tic-tac 0 olist expr-list]
>                (let [item (first olist)]
>                        (if (= item nil)
>                                (list flist slist)
>                                (if (= tic-tac 0)
>                                        (recur (concat flist (list item))
> slist 1 (rest olist))
>                                        (recur flist (concat slist (list
> item)) 0 (rest olist)))))))
>
> Test:
>
> (def dl (interleave (iterate inc 1) ["A" "B" "C" "D" "E"]))
> (unravel dl)
>
> And the "classic" question is it possible to do it simple, more in a
> "functional manner", without explicit looping?
>

(defn unravel [s]
  [(take-nth 2 s) (take-nth 2 (rest s))])


Christophe

-- 
Professional: http://cgrand.net/ (fr)
On Clojure: http://clj-me.cgrand.net/ (en)

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