Hi clojure-world,
I think maybe this is actually related to the complexities of binding
referenced in the previous thread
(https://groups.google.com/forum/?utm_source=digest&utm_medium=email#!topic/clojure/zBXsrqTN2xs)...
maybe? But it would be amazing if some wise person would help explain...
So for obscure reasons, I found myself trying to use a naive recursive
fibonacci function interactively. So naturally, the first thing my fingers
went to was:
(let [fib (fn [x]
(cond
(< x 2) x
:else (+ (fib (- x 2)) (fib (- x 1)))))]
(fib 5))
which threw an unable to resolve symbol error because it couldn't resolve
the recursive calls to fib inside the let binding.
But swap out the let for a def and it works just fine:
(def fib (fn [x]
(cond
(< x 2) x
:else (+ (fib (- x 2)) (fib (- x 1))))))
(fib 5)
Can someone clarify for me what's going on here? Why can a def binding get
access to its own name in the body of a function, but not a let binding?
thanks!
-Paul
--
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/d/optout.