I have developed a library which places Java objects into clojure vars.
This is all working nicely, but I would like to documentation look up to
work as normal. I *could* add documentation using the normal metadata
facilities, but this is not ideal because the Java object itself
contains documentation, and I want it to be the same.

So, I have tried all sorts to achieve this. My latest attempt was to do this:


(defrecord CallbackString [f])

;; add to the default print-method, so that the function is called, and the
;; results are printed.
(defmethod print-method CallbackString [o, ^Writer w]
  (let [string
        (try
          ((:f o))
          (catch Exception e
            (str "Unable to capture doc from OWL object: " e)))]
    (.write w string)))

Now instead of putting a string as a :doc entry, I put a CallbackString.
This contains a closure, which contains the Java object; any attempt to
print the :doc metadata of the var, therefore calls appropriate java
method calls.

Nice, but this only works when doing "(print (:doc m))". Any other
access of the metadata gets the function. So apropos will fail.

It also massively complicates my macros; these used to use "def" but the
metadata is needed at compile time to create the symbol, at which point
the value (where I need) is not available. So, now these use "intern"
instead. However, intern does not put file, line and column metadata
onto the symbol as def does.

So my last attempt to solve this problem is to calculate the doc string
once, and add it to the existing var. The best that I have got here is this:

(def test-without-doc "hello")

(doc test-without-doc)
(println (meta (var test-without-doc)))

(intern *ns*
        (with-meta
          'test-without-doc
          (merge
           (meta (var test-without-doc))
           {:doc "Now we have documentation"})))


(doc test-without-doc)
(println (meta (var test-without-doc)))


But I am worried about this reinterning; I'm not sure why the value is
retained, and am concerned that this might change in future.

Is there any other solution I am missing?

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.


Reply via email to