On Oct 2, 12:23 pm, Meikel Brandmeyer <m...@kotka.de> wrote: > Hi, > > Am 01.10.2009 um 19:08 schrieb Rich Hickey: > > > > > > > It simply doesn't compose or flow. Making the nil env special (e.g. > > non-replacing) just moves the problem into higher-order functions that > > use the construct: > > > (defn needs-x [] > > (use-env-x)) > > > (defn needs-y [] > > (use-env-y)) > > > (defn foo [] > > (with-env x (fn [f] (needs-x) (f)))) > > > (let [f (foo)] > > (with-env y (f needs-y))) > > > needs-y isn't going to get it. > > This is "simply" solved by having a chain of environments. The > algorithm works like this: > > * The desired value is contained in the current map. => Use it. > ("Younger" bindings override "older" ones) > * The desired value is not contained go up one step in the chain of > env maps and repeat. > * If there is no further step in the chain (ie. we arrived at nil), > use the root binding of the Var. > > "simply" with quotes, because I have no clue about the performance > impact of that. It should fix your example, though. >
Yes, I know how linked environments work, and in Clojure you wouldn't do that but would instead just assoc onto the incoming env map. Then at least lookups will remain fast. But environment extension will still be an overhead, and more important will persist even if not needed. E.g. it still has scope issues, since when someone says (with-env x ...) they have an expectation of the dynamic extent of the binding ending with the block, and it won't necessarily if any closure/laziness escapes. (defn bar [] (fn [] (doesnt-use-big-thing))) (defn needs-a-big-thing [] (use-a-big-thing) (bar)) (defn foo [] (with-env a-big-thing (needs-a-big-thing))) ;a-big-thing is kept around needlessly Overall these requests just seem to be - I wish dynamic binding knew what I needed and did it (only when I need it to), without any real semantics. Note that I am interested in a construct with useful semantics, but we need to get some semantics before implementation details. Rich --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---