Hi..I've a little problem using recur for recursive calling...I'm
trying do the clojure koans and the recursive reverse function
[1 2 3 4] -> '(4 3 2 1)
first I try this code:
(defn recursive-reverse [coll]
(loop [col coll mem '()]
(if (empty? coll)
mem
((cons (last col) mem)
(recur (butlast col) mem) ))))
this didn't work and I thought the problem was (butlast col) and
rewrite the code to this
(defn recursive-reverse [coll]
(loop [col (butlast coll) mem (list (last coll))]
(if (empty? coll)
mem
((cons (last col) mem)
(recur col mem) ))))
why isn't a tail recur?...my recursion is de latest operation in the
functin
thanks so much
I hope learn a lot about functional programming
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en