On Tue, Jan 20, 2009 at 12:53 AM, Timothy Pratley <timothyprat...@gmail.com> wrote: > > >> How would one go about fixing f1 (or b1)? > > Depends what you want to achieve... here are two possible 'fixes': > > ; don't use lazy evaluation > (defn f1 [] > (doall (map (fn [x] *num* ) [1]))) > > ; use lazy evaluation, but preserve the binding when the lazy sequence > is created > (defn f1 [] > (let [mynum *num*] > (map (fn [x] mynum) [1]))) > >
Yes, these work. They presume the author of f1 knows that the caller is liable to rebind *num*. Is it always going to be unsafe to use Vars in a lazily evaluated function? If so, could the compiler or runtime automate forcing doall or let? I'm understanding better. The caller can also do (binding [*num* 1024] (doall (f1))) The caller doesn't necessarily know he's getting a lazy sequence back, but this would be a boilerplate pattern you use anytime you use binding. Again, could/should Clojure automate doing that? Thanks all for the insights. Hugh --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---