On Jan 23, 2009, at 11:52 AM, Konrad Hinsen wrote:

Some questions this raises:

- Should libs be restricted to definitions (and lib support things
like "ns" and (some kind of) "load-resource") only?

- Should the appearance of an "ns" form automatically make that
restriction enforced for the rest of "this file" (as it's being
loaded).

That would require an operational definition of what counts as a
"definition", which moreover can be verified by the compiler. I am
not sure that is realistic. Pretty much any Clojure function except
for I/O can be used in definitions, so your suggestion comes down to
making the compiler recognize any attempt to do I/O, even indirectly,
and even then make an exception for things like load-file.

Good point. I had been thinking mostly of definition of functions where in the simple case, all actual operation is deferred until the function is called. One basic way to view "what counts as a definition" is something that ultimately invokes "def". On the way to invoking def, one could also allow compiling code, but not running it, deferring initializers until some kind of "load" time. Macros present a problem with this strategy, of course, and I gather they're the primary reason why code has to be loaded as well as compiled in Clojure's "same world" compilation process currently.

Would some kind of Java sandbox to compile in be an effective way to implement a (macroscopically) more functional way to use the existing compiler to accomplish goals along these lines? Certainly if a different JVM instance were used, that should be an effective way to separate what happens at compile time from the operation of Clojure instance supporting an IDE session.

The familiar compile/load/run separation in Java and C++ (where compile is purely functional and load calls static initializers) has some nice benefits. I'm guessing if it were easy to accomplish with Clojure, Rich might have gone that way initially.

As a guideline your suggestions seem fine though. I wouldn't like to
work with libraries whose mere import does something magical.

Thanks.

- Do we need a mechanism like java's "main" method where we could
put any scripting code (things intended to "do" something when the
lib is used as a script) rather than allowing non-definitions
everywhere? We could by convention call a particularly named
function or we could provide the name (or signature?) of a
designated function in the "ns" form and call that when calling
(effectively) a namespace as a "program" rather than "using" it as
a "library":

        (ns my-simulator
                (:require 'clojure.contrib.lazy-seqs)
                (:main do-simulation [circuit inputs]))

That sounds nice.

One further thought on that is that an argument to :main should probably just be a name rather than a name and argument list because the argument list(s) will already appear along with the "defn" of the name.

--Steve

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

Reply via email to