Thanks Howard. Another great answer.
Morten
On Nov 12, 2:58 am, Howard Lewis Ship wrote:
> Symbols are late resolved to functions.
>
> (def t (fn ...)) means define a Var bound to symbol t, and store the
> function in it. In JVM terms, the function becomes a new class that is
> instantiated.
>
>
Great answer Alex. Thanks!
Morten
On Nov 12, 12:34 am, Alex Osborne wrote:
> mbrodersen wrote:
> > In this simple recursive expression:
>
> > (def t (fn [x] (if (zero? x) 0 (+ x (t (dec x))
>
> > The fn special form is evaluated within a context where t is not yet
> > bound.
>
> > t is only
Symbols are late resolved to functions.
(def t (fn ...)) means define a Var bound to symbol t, and store the
function in it. In JVM terms, the function becomes a new class that is
instantiated.
(t (dec x)) means locate the Var bound to symbol t -- at execution
time (not compilation time) --- de-r
Hi,
On Nov 11, 2:34 pm, Alex Osborne wrote:
> (let [t (fn [x] (if (zero? x) 0 (+ x (t (dec x)] (t 2))
But also note, that you can give an anonymous function a name. %)
(let [t (fn t [x] (if (zero? x) 0 (+ x (t (dec x)] (t 2))
Sincerely
Meikel
--
You received this message because you
mbrodersen wrote:
> In this simple recursive expression:
>
> (def t (fn [x] (if (zero? x) 0 (+ x (t (dec x))
>
> The fn special form is evaluated within a context where t is not yet
> bound.
>
> t is only bound AFTER fn has captured its environment.
>
> In other words, the closure captured
A quick question about how closures work in Clojure.
In this simple recursive expression:
(def t (fn [x] (if (zero? x) 0 (+ x (t (dec x))
The fn special form is evaluated within a context where t is not yet
bound.
t is only bound AFTER fn has captured its environment.
In other words, the c