I know this fibonacci function is not optimal but I want to learn one step 
at a time.  I want to be able to apply this approach to 4clojure which 
disallows a lot of things including defn. 

This is my implementation so far: 

(defn fib [x] 
   (cond 
      (= x 0) 0 
      (= x 1) 1 
      :else 
         (+ (fib (- x 1)) (fib (- x 2)))))


So I thought about something like this:

(#(fn fib [x] 
   (cond 
      (= x 0) 0 
      (= x 1) 1 
      :else 
         (+ (fib (- x 1)) (fib (- x 2)))))
              8)

But trying that in a REPL I get error:

clojure.lang.ArityException: Wrong number of args (1) passed to: 
sandbox28956$eval28971$fn

So how can I call this as a one line REPL?

I though using apply with a one element list might work, but no.

(apply #(fn fib [x](cond (= x 0) 0 (= x 1) 1  :else  (+ (fib (- x 1)) (fib 
(- x 2))))) '(8))


-- 
-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to