The arguments 'n' and 'e' to the calls to findFib on lines 7 and 8 are
enclosed in parens, causing them to be treated as lists. Clojure expects the
first element in a list to be a function and is therefore trying to cast it
to an IFn which of course fails.
I think this is what you are looking for:
(defn findFib
"Find the sum of all the even-valued terms in the sequence which do
not exceed four million."
[e n p]
(if (< n 1000000)
(if (= (rem n 2) 0)
(findFib (+ e n) (+ n p) n)
(findFib e (+ n p) n))
(str "Value is " e)))
Please note the absence of parens around the third argument to findFib on
line 7 and around the first and third arguments to findFib on line 8.
Best,
Siddhartha
On Mon, Oct 19, 2009 at 8:22 PM, Peregrine <[email protected]> wrote:
>
> Hey I am new to Clojure and I am doing some Project Euler problems to
> help me get started with the language. I've run into a issue I cannot
> seem to get past. I have this code:
>
> (defn findFib
> "Find the sum of all the even-valued terms in the sequence which do
> not exceed four million."
> [e n p]
> (if (< n 1000000)
> (if (= (rem n 2) 0)
> (findFib (+ e n) (+ n p) (n))
> (findFib (e) (+ n p) (n)))
> (str "Value is " e)))
>
> And I keep getting this error
>
> 1:9 problem2=> (findFib 0 1 2)
> 1:10 problem2=> java.lang.ClassCastException: java.lang.Integer cannot
> be cast to clojure.lang.IFn (repl-1:9)
>
> I know my code may be incorrect to find the issue at hand but I cannot
> get passed this issue.
>
> Can anyone help?
>
> Thanks!!
> peregrine.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---