"Jim - FooBar();" <jimpil1...@gmail.com> writes: > funny you should mention that!!! that is exactly what I meant by 'my > fault'...I've come to realise that dynamic scope is almost evil, thus > I go to great lengths to avoid it completely...in the rare cases where > I do use it I always make sure it is bound to a init/default value :)
I do exactly the opposite when I use dynamic vars, that is, I define no default value. For example, there's a function foo that uses a dynamic var, and that must be bound and well-defined. Therefore, I provide a macro to initially set it up, so that you write (with-bar (foo bla)) and with-bar takes care of the proper initialization of that dynamic var (which is not even visible to the user). When foo explodes because of the var being Unbound, then it's obvious that the function was called outside a with-bar macro and thus is a user error. A default value would shadow such an error. A real-world example of this design are many database query libs, where you frequently have code like (with-db-connection (make-me-a-db-connection url) (select :from "foo" :where ...)) Bye, Tassilo -- -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.