(ns src.helloworld)
(defn fibonacci[a b] (println a b (fibonacci (+ b 1) a + b)))
(fibonacci 0 1)
I’m new to Functional Programming and decided to start learning Clojure as it’s very different from C#. I’d like to broaden my horizons.
Here’s the error I get:
Clojure 1.2.0
java.lang.IllegalArgumentException:
Wrong number of args (4) passed to:
helloworld$fibonacci
(helloworld.clj:0) 1:1 user=>
#<Namespace src.helloworld> 1:2 src.helloworld=>
Math problems never were my strong suit and I never really made anything that manipulated numbers like this, so I would like any guidance you can give.
Please don’t give me the entire solution.
Preferably I would like some good hints and maybe a skeleton of how it should look like.
The other answers explain to you the error in your function call. After fixing that you should look into using loop/recur which will do tail call optimization and thus not use the stack for each recursive call. It would be pretty hard to give an example without giving you the whole thing though :-/ Here is another thread where they calculate a factorial using recursion in clojure: Factorial