There was a thread a little while back
(http://groups.google.com/group/clojure/browse_thread/thread/8c4bea21298693ca)
about implementing true data hiding by nesting defns under a let,
e.g.:
(let [hidden-ref (ref 10)]
(defn get-secret [] @hidden-ref))
This was mentioned to be bad style. If this is the general consensus,
what suggestions do you have if you want to write a macro which
generates a Java class using (genclass) and also generates default
implementations for some getter and setter methods?
For example, I want to write a macro that transforms:
(defbean MyBean :myint 0, :mystring "default")
into something like:
(gen-and-load-class "MyBean" ...)
(defn MyBean-getMyint [this] ...)
(defn MyBean-setMyInt [this value] ...)
(defn MyBean-getMystring [this] ...)
(defn MyBean-setMystring [this value] ...)
However, in order to do this, the macro needs to expand to something like:
(do
(gen-and-load-class "MyBean" ...)
(defn MyBean-getMyint [this] ...)
(defn MyBean-setMyInt [this value] ...)
(defn MyBean-getMystring [this] ...)
(defn MyBean-setMystring [this value] ...))
In my case I've been wrapping this in a (let) as there are some locals
that I need to setup in order to fill in the templates for the getters
and setters.
I'm wondering if there is a different way, in light of the dislike for
placing (defn) in a nested structure instead of the top-level.
Thoughts?
/mike.