Jim <[email protected]> writes:
> On 16/05/13 11:33, Phillip Lord wrote:
>> And if it is okay to use set!
>> on*warn-on-reflection*, why is it not okay to allow me, as the library
>> developer, to define similar properties for my library which work in a
>> similar way.
>
> well, nothing stops you from providing bindings at the main entry point of
> your library, much in the same way that Clojure does...then consumers can use
> set! as you expect. That said, I wouldn't go down that road simply because it
> gives that 'global-state' smell...
I don't have a main entry point. And, yes, I want global-state for
exactly the same reason that Clojure does. I have a process that
produces logging output, and I want the user to be able to define
where that output goes. Basically, the same as doing:
(set! *out* some-sensible-value)
but different because I also want to be able to choose between a
GUI output, and text.
So, I guess, my two options are:
(def
^{:dynamic true}
*can-we-change-it* (atom "John"))
(println @*can-we-change-it*)
(reset! *can-we-change-it* "Paul")
(println @*can-we-change-it*)
(binding [*can-we-change-it*
(atom "George")]
(println @*can-we-change-it*))
(println @*can-we-change-it*)
(def
^{:dynamic true}
*can-we-change-this-one* "Mick")
(println *can-we-change-this-one*)
(alter-var-root #'*can-we-change-this-one*
(fn [x] "Keith"))
(println *can-we-change-this-one*)
(binding [*can-we-change-this-one*
"Bill"]
(println *can-we-change-this-one*))
(println *can-we-change-this-one*)
Of which, I think, the former is the best option, although it's going to
break my existing code which uses binding forms.
Phil
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.