(This is sort of a follow-up to this thread from last July:
http://groups.google.com/group/clojure/browse_thread/thread/7f5cf3e78954b81d/aae7f082c51337c9?lnk=gst&q=proxy#aae7f082c51337c9.)

Recently, I've been building a version of java.io.Writer that knows
what the
current column is on the output so it can handle tabs, etc.

It would be pretty easy to do this with AOT, :genclass, etc. and just
have a ref
to the column number in my state, but life seems easier if you don't
have to use
AOT, so I considered doing it with a proxy.

However, proxies *only* support the methods provided by their super-
classes. They
do this so that the proxy class can be compiled once, making proxy
intances and
variation super-cheap.

I dug through the code in core_proxy.clj while trying to learn about
this and it
occurred to me that proxies could add state (similar to that created
in
:gen-class) with the following changes:

1) Add a __clojureProxyState field that points to a ref to a map, but
is initialized to
nil.
2) Add a getClojureProxyState() method to IProxy that returns the ref
in question, lazily
instantiating (ref {}) if necessary.

Of course, the ref to a map thing is optional. The state could be left
open as
in :gen-class.

This seems like it would add this capability without much problem. It
has a few
issues I can see:

* We're a functional language so more places to add state are against
the base
  philosophy.
* The lazy instantiation could race (but that might be fixable).
* The new names increase the chance of name collison.

I'm interested to hear what folks think. If this was a capability that
Rich and
others agreed was a good addition, I'd be happy to build it and crank
out a
patch for it.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to