Re: recursive bindings not available in let form?

2016-12-04 Thread Timothy Baldridge
Let bindings map pretty much directly to Java style local variables: (let [x 42] (let [x 3] (+ x 3)) Becomes something like this when compiled to byte code: x_1 = 42 x_2 = 3 return x_2 +3 So let bindings with the same names are kept separate via modifying the stored name in the byte

Re: recursive bindings not available in let form?

2016-12-03 Thread Paul Gowder
That's a really neat post. Thank you for writing it! How do bindings created by let fit into that picture? > The question of how vars work comes up enough that I recently wrote a blog > post on the subject. Maybe it will be useful to you. >

Re: recursive bindings not available in let form?

2016-12-03 Thread Timothy Baldridge
The question of how vars work comes up enough that I recently wrote a blog post on the subject. Maybe it will be useful to you. http://blog.cognitect.com/blog/2016/9/15/works-on-my-machine-understanding-var-bindings-and-roots Timothy On Fri, Dec 2, 2016 at 2:44 PM Paul Gowder

Re: recursive bindings not available in let form?

2016-12-02 Thread Mark Engelberg
Your "y" could also be "fib". You are permitted to use the same name inside the fn. On Fri, Dec 2, 2016 at 12:59 PM, Walter van der Laan < waltervanderl...@gmail.com> wrote: > AFAIK there are two options. > > You can add a symbol after fn: > > (let [fib (fn y [x] > (cond >

Re: recursive bindings not available in let form?

2016-12-02 Thread Paul Gowder
Thanks Bobby, Francis, Walter! Now trying to wrap my head around the idea of def as a ref... On Friday, December 2, 2016 at 2:57:13 PM UTC-6, Francis Avila wrote: > > Let bindings are immutable bindings, not refs. They must act as if their > value could be substituted at the moment they are

Re: recursive bindings not available in let form?

2016-12-02 Thread Walter van der Laan
AFAIK there are two options. You can add a symbol after fn: (let [fib (fn y [x] (cond (< x 2) x :else (+ (y (- x 2)) (y (- x 1)] (fib 5)) Or, as Bobby already suggested, you can use letfn: (letfn [(fib [x] (cond (<

recursive bindings not available in let form?

2016-12-02 Thread Francis Avila
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

Re: recursive bindings not available in let form?

2016-12-02 Thread Bobby Eickhoff
Note that letfn does allow recursive bindings, though I couldn't comment as to the implementation details. On Friday, December 2, 2016 at 3:01:13 PM UTC-5, Paul Gowder wrote: > > Hi clojure-world, > > I think maybe this is actually related to the complexities of binding > referenced in the

recursive bindings not available in let form?

2016-12-02 Thread Paul Gowder
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_medium=email#!topic/clojure/zBXsrqTN2xs)... maybe? But it would be amazing if some wise person would help explain...