On Jan 16, 2009, at 11:37 AM, Chouser wrote:
It would also be useful for a .clj file to be able to determine if itself is the main script or if instead it's being loaded some other way (-i, load-file, require, etc.).
How about this which is not quite the same, but has nice properties of its own:
It appears that all flavors of loading ultimately bottleneck at Compiler.load(Reader,String,String). We could add a "*load-level*" var with a root binding of 0 that gets incremented on each entry to that Compiler.load method. A *load-level* of 1 would indicate that this file is being loaded from the "top level" with no other load pending.
A script could behave differently on (= *load-level* 1) (or a suitably named function that returns the same boolean value).
I like this because it's simple to implement and explain and it also covers the case of loading a script explicitly from the repl. Arguably a script loaded by the user from the top level at the repl ought to behave as a "main" script as well.
--Steve
smime.p7s
Description: S/MIME cryptographic signature