On 15.02.2009, at 06:26, Chouser wrote:
> > On Sat, Feb 14, 2009 at 11:32 PM, GS <gsincl...@gmail.com> wrote: >> >> On Feb 14, 12:21 pm, Chouser <chou...@gmail.com> wrote: >>> >>> (defn count-instances [obj lsts] >>> (let [instances-in (fn thisfn [lst] >>> (if (seq lst) >>> (+ (if (= (first lst) obj) 1 0) >>> (thisfn (rest lst))) >>> 0))] >>> (map instances-in lsts))) >> >> Notwithstanding your more idiomatic implementation (snipped), >> wouldn't >> "recur" be better than "thisfn"? >> >> (defn count-instances [obj lsts] >> (let [instances-in (fn [lst] >> (if (seq lst) >> (+ (if (= (first lst) obj) 1 0) >> (recur (rest lst))) >> 0))] >> (map instances-in lsts))) > > Yes, you're absolutely right. however, the recur isn't in tail position, so it doesn't work: user=> (defn count-instances [obj lsts] (let [instances-in (fn [lst] (if (seq lst) (+ (if (= (first lst) obj) 1 0) (recur (rest lst))) 0))] (map instances-in lsts))) java.lang.UnsupportedOperationException: Can only recur from tail position (NO_SOURCE_FILE:12) all the best, --Chris --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---