suggest new (method-map ...) function

0 views
Skip to first unread message

jon

unread,
Apr 5, 2008, 4:35:47 PM4/5/08
to Clojure
Would it be a good idea to add a function like this to the standard
library, to allow an "official" way to lookup individual methods (as
opposed to only knowing the multi-method as a whole), and therefore
facilitate more precisely targeted aspect/context-style wrapping --
ie. for logging, tracing, monkey-patching(?), etc?

(defn method-map [multifn]
(. multifn methodTable))

-------------------------------------------------------------------
user=> (method-map area)
{:Rect clojure.fns.user.fn__1080$fn__1082$fn__1084@c5d9c1, :Circle
clojure.fns.user.fn__1089$fn__1091$fn__1093@15b4ad2, :default
clojure.fns.user.fn__1098$fn__1100$fn__1102@8d3d62}

user=> (def area-circle ((method-map area) :Circle))
#<Var: user/area-circle>

user=> (area-circle c)
452.3893421169302
-------------------------------------------------------------------
Thanks,
Jon

Rich Hickey

unread,
Apr 5, 2008, 4:54:45 PM4/5/08
to Clojure


On Apr 5, 4:35 pm, jon <superuser...@googlemail.com> wrote:
> Would it be a good idea to add a function like this to the standard
> library, to allow an "official" way to lookup individual methods (as
> opposed to only knowing the multi-method as a whole), and therefore
> facilitate more precisely targeted aspect/context-style wrapping --
> ie. for logging, tracing, monkey-patching(?), etc?
>

At some point there will be a proper function-based interface to the
multimethods, and something like (find-method multi dispatchval).

Along with that will be a relationship between a method and a var, and
any kind of runtime/context based wrapping will use the standard var
binding stuff.

But not now, and until then you should consider the implementation of
multimethods opaque and subject to change.

Rich

jon

unread,
Apr 5, 2008, 5:47:47 PM4/5/08
to Clojure
Ok, sounds good.

Do you think a 'Planned features' page on the clojure site would be a
worthwhile addition?
eg.
Categorized into:
- High priority (planned to be added in the forseeable future)
- Low priority (nice-to-have's with no current timeframe)
and possibly
- Non-goals (these features are not objectives of clojure and unlikely
to be added)

I think several of all of these have been mentioned.
Cheers, Jon

Rich Hickey

unread,
Apr 6, 2008, 9:44:21 AM4/6/08
to Clojure


On Apr 5, 5:47 pm, jon <superuser...@googlemail.com> wrote:
> Ok, sounds good.
>
> Do you think a 'Planned features' page on the clojure site would be a
> worthwhile addition?

I think it would only add unwelcome pressure to my life :)

Rich
Reply all
Reply to author
Forward
0 new messages