On Sun, 20 Mar 2011 08:47:30 -0700 (PDT) Christian <soulbea...@gmail.com> wrote:
> Hello Tassilo! > > I've tested your code and looked at the Clojure Documentation for > 'for'. Given that, I have written > > (reduce +(filter even? (for [fib (fib-seq) :while (< fib 4000000)] > fib))) > > This gives me the error 'clojure.lang.LazySeq cannot be cast to > clojure.lang.IFn'. > > I think this is because fib-seq is a var, not a function (although I > was hard-pressed finding out what IFn stood for.) When I omit the () > with [fib (fib-seq)...], the program works just as expected. Since nobody answered the implied question: yes, you're right. The fix is to just remove the ()'s from fib-seq to reference it directly, like so: (reduce + (for [fib fib-seq :while (< fib 4000000) :when (even? fib)] fib)) Note that I replaced the filter with the for loops :when test. No real reason, it just feels more natural to use what for offers since you started with it. Personally, I'd probably use Daniel's filter/take-while solution. <mike -- Mike Meyer <m...@mired.org> http://www.mired.org/consulting.html Independent Software developer/SCM consultant, email for more information. O< ascii ribbon campaign - stop html mail - www.asciiribbon.org -- 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