clojure - How to make namespace alias available after initial compile time? -
I am working on a Closer app which needs to be able to read the closer code from the shell command line. The app has a - main
function that reads a string on the command line with a single closure form, and passes this string to the closure function load-string
Which parses string and executes the code, it is successfully using both using lean run
and uberjar.
I've found that the code given on the command line may include full-name namespace names if the code at the top of the file containing the name space <<>> main > required < / Code>. For example, if the source file starts with
(ns popco.core.popco (: [popco.core.reporters: as rpt])
< / Pre>The string I pass on the command line can refer to my function
ticker
popco.core.reporters / ticker
However, I can not use the nicknamerpt
if I am referred to by theticker
rpt / ticker
, I get an exception:java. Lang.RuntimeException: No such namespace: rpt
.I am feeling that this is because the nickname is available only on time compilation, and only one compilation time since the string of code of the code is compiled at that time, Since the compilation of the source file has been completed,
rpt
is no longer available as a nickname.A solution that lets me use name space aliases Allows
requirement
at the top of the file (which I run in repl Within want to use I)-Main
. However, there are many namespaces that I might need to include, and the duplicate code is undesirable.Is there any other solution? Once a method of defining aliases, when available in both, while running the code from the command line and running in both of them?
(Edit: Analysis can not be perfect at the time of compiling the above - or maybe I can not understand the closure compilation. (Actually, I could not understand Closer compilation! ) In the solution outlined in the two paragraphs given above,
requirement
- main
in the original source code, not only the string withload-file
passed Therefore,requirement
is being compiled when-man
has been compiled, I think, which will be in the form of the top of the source file during the same pass, I think. Still the code inside any of the code-man
From if the code was typed in the definition of-man
, but if it has been brought through theload-file
, neverthelessload-file
is under the nickname when([popco.core.reporters: as rpt] is required)
-man is in the source code for
. Why?)
Alias
function, which requires the system alias
.
This is the reason that the requirement
of <0> defines the embedded in the manner expected by you to make the nickname: it can be used to mutate your runtime name space. To include the given nickname is strongly needed, it does not necessarily change the popco.core.popco
namespace! In fact, this is unlikely to be a name space working on runtime, when -man
is applied (it happens at the time of compile , and thus, like That changing the definition of the ns
macro, ns).
The key here is to realize that ns
always ns
on the runtime defines your -man
function, And if you want to change the evaluation environment in the runtime, then you have to switch to the namespace you are mutating, or change the namespace you are in.
Comments
Post a Comment