I haven't tested it or anything, but you can use:
(extend-type java.util.Properties
ILookup
(valAt [this key] ...)
(valAt [this key not-found] ...))
AFAIK you can extend on Interfaces but not Abstracts or Classes.
On Mar 6, 9:27 pm, kurtharriger <[email protected]> wrote:
> I was curious if it was possible to extend keyword lookup behavior to
> additional types, such as java.util.Properties.
>
> Currently I just convert java.util.properties into a keyword map with
> something such as the following.
> (defn as-keyword-map [prop]
> (into {} (for [[k v] prop] [(keyword k) v])))
>
> This works well enough but I thought this might be possible to extend
> keywords or java.util.Properties via protocols or something to change
> the implementation of (:access-key prop) to (.get "access-key" prop).
> Its easy enough to redefine get using multimethods so that (get
> prop :access-key) would work on any type I wanted but I couldn't
> figure out how to do the same with keywords. Looking at keyword.java
> it expects that object implements ILookup so I tried using (extend-
> type java.util.Properties Lookup ...) however ILookup isn't a protocol
> so this doesn't seem to work.
>
> I'm beginning to think that implementation of keywords being
> implemented in java doesn't support clojures more advanced
> extensibility features. This makes me wonder if using the more
> idiomatic (:access-key obj) instead of (get obj :access-key) also
> limits my future extensibility options. Is there a way to do this
> that I haven't thought of? and would it be possible to make ILookup
> into a protocol to enable this type of extensibility?
--
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