On Sat, Aug 7, 2010 at 8:27 PM, David Cabana <drcab...@gmail.com> wrote:
> Using a vector instead of a list as the accumulator makes it possible
> to skip the mapping of reverse used in the earlier version of pw:
>
> (defn pw [f? x]
>  (let [phi (fn [a e]
>              (if (f? e)
>                (cons [e] a )
>                (cons (conj (first a) e)
>                      (rest a))))]
>    (reverse
>     (reduce phi []  x))))
>

conj sounds like 'append' to me which I have no idea about the
performance characteristics in clojure(it is a no-no in F#, Haskell ++
is better but would grow the stack). list cons then reverse would give
me predictable O(2n). That is why I usually rather go for the cons
then reverse route.

thanks for the example BTW, as I am learning my clojure basics via
these excercises.

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