Let bindings are immutable bindings, not refs. They must act as if their value
could be substituted at the moment they are referenced. Def (i.e. a ref) is a
mutable container whose contents is examined when it is used (not when
referenced), which is why your second example works.
Why doesn't let work how you expect? Well, how would the following code work if
let worked as you intend?
(let [a 1
a (+ a 2)]
(= a 3))
However, fn accepts an optional name binding, so you can do this:
(let [fib (fn fib [...] (fib ...))] fib)
The inner fib reference is bound by the fn form, but the outer fib reference is
still bound by let.
Or you can use letfn instead of let, which is the same as above with less
typing AND the bindings can all see one another simultaneously. It's best for
groups of closed-over but mutually recursive functions.
(letfn [(fib [...] (fib ...))] (fib ...))
--
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.