On Jul 4, 2009, at 4:02 AM, Meikel Brandmeyer wrote:

Is there some specific reason for that or could load be adapted to also return the last value evaluated?

I experimented with this, got it to work for a simple case, and prepared my initial reply below. In working with the idea some more though, I think there is a show-stopper problem with it. In the case of an AOT compiled Clojure file, it's loaded (ultimately) with Class.forName. I don't see a way to retrieve the last eval'd expression from such a load.

I now think the idea of returning a usable value from load is not reliable/general enough to be worth doing.

For the case you described, I recommend the method I described below: require the plugin file to define a function with a well-known name in its namespace and call that function after loading the plugin.

--Steve

my initial reply:

load could be adapted. I experimented and I have it working on my machine. The several variants of loadResourceScript and load in RT.java need to be changed to return Object. Also, clojure.core/load currently supports loading multiple libs with one call, but apparently that's never used in clojure.core or clojure.contrib. Changing its signature to accept only one lib name would facilitate returning a value. I did that in my experiment and all tests still pass.

I see returning a value from load as a nice functional thing to do. On the other hand, I view loading as primarily state-changing: adding to the capabilities of the running Clojure by loading in libs that implement namespaces. To the greatest extent possible, I think Clojure source files should contain only definitions--a view that embraces a clear distinction between load/compile time and run time.

In the case you describe, I think it would be clearer to require that your plugin files define a function with a specified name (like "plugin-info") that can be called after they are loaded to return the info you require. This would be similar to having Java plugins implement a "de.kotka.Plugin" interface (for example). This would make your intention for these files explicit both within their body and in your plugin loading code.

All that being said, I think changing the "load" suite of functions in clojure.core and clojure.lang.RT to return the last thing evaluated would make Clojure strictly more powerful and I'll be happy to provide a patch if an issue requesting it is welcome.

--Steve

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to