Hi, On 17 Nov., 16:29, David Sletten <da...@bosatsu.net> wrote:
> > => (defn a > > ([x] x) > > ([x y] (+ (a x) (a y)))) > > #'user/a > > => (a 1 2) > > 3 > > => (def b a) > > #'user/b > > => (b 1 2) > > 3 > > => (defn a [x] > > (- x)) > > #'user/a > > => (b 1 2) > > -3 > > Let's call the original function assigned to 'a' a0 and the new one a1. After > 'a' has been redefined to a1, 'b' still refers to a0. So the 2nd call to 'b' > invokes a0 with two args (in fact, a1 only takes one arg now). But within a0 > itself the references to 'a' are being resolved at runtime to a1 now, not as > references to a0 as before. > > Are you saying that inside a0 Clojure detects that 'a' means something else > now and recompiles a0 to point to a1? > > In any case, this behavior seems weird. Isn't that completely logical? Let's name things differently to keep functions and Vars apart. You define a function f and store it in Var a. f references Var a internally. Then you define Var b and store f in it by retrieving it from Var a. By executing (b 1 2) you basically retrieve f from b and call it with two arguments. Inside f, f itself is retrieved from the Var a and called with one argument. Now you create a new function g, which you store in Var a (assumption: re-defing an existing Var just replaces its value and does not unmap and map again a fresh Var). Again you execute (b 1 2). Same thing happens: f is retrieved and called with two arguments. Inside f however, now g is retrieved from Var a and called with one argument. This actually allows to define memoized recursive functions. Sincerely Meikel -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en