Thanks, Juan. I saw that it was a compile time error after I sent out the
email, so I tried to run it through "eval", and even this works. But,
"resolve" looks more idiomatic. Also, I'll have to figure out how to get
the namespace of the loaded file next.

(eval (read-string (str "(do (load-file \"" (first args) "\")
(hello/someconst))"))))


Thanks,
ramesh


On Sun, Oct 20, 2013 at 1:22 AM, juan.facorro <[email protected]>wrote:

> Hi Ramesh,
>
> Based on the stack-trace, the error is thrown during compile-time. This
> means the compiler is having a hard time compiling test1/core.clj because
> it doesn't know of any hello namespace. This makes sense since no hello 
> namespace has
> been referred to in the test1.core namespace (i.e. the file being
> compiled). Note that the call to ns-publics works because you are
> actually using the quoted symbol hello which the compiler doesn't have to
> resolve.
>
> In order to get the value of the vars in hello at runtime (after loading
> the file) you can use the resolve or the intern functions, which return
> the var (not the value) from the given namespace, so you have to dereference
> it:
>
>    (println (-> 'hello/someconst resolve deref))
>
> Also, if the hello.clj  file is in the src dir, you should run:
>
>   lein run src/hello.clj
>
> Which show this output:
>
> #<Namespace hello>
>  {-main #'test1.core/-main}
> {someconst #'hello/someconst}
> #<hello$someconst hello$someconst@cdc69b>
>
>
>
> HTH,
>
> Juan
>
>
> On Sunday, October 20, 2013 11:49:27 AM UTC+8, Ramesh Thulasiram wrote:
>>
>> Hi All,
>>
>> I'm calling load-file to load a user-specified file inside -main. And,
>> the loaded file has its own namespace, and I'm able to see that using
>> (ns-publics) as well. However, when I try to call a function inside the
>> loaded file, from -main, I'm getting a "no such namespace" exception.
>>
>> ;; Lein project test1;File : src/test1/core.clj(ns test1.core 
>> (:gen-class))(defn -main [ & args]   (load-file (first args))  (println 
>> (ns-publics 'test1.core))  (println (ns-publics 'hello))  (println 
>> (hello/someconst))) ;File : hello.clj(ns hello)(println *ns*)(defn someconst 
>> [] 25); run as : ; lein run hello.clj(comment error  Exception in thread 
>> "main" java.lang.RuntimeException: No such namespace: hello, 
>> compiling:(test1/core.clj:9:12**)        at 
>> clojure.lang.Compiler.analyze(**Compiler.java:6380)  at 
>> clojure.lang.Compiler.analyze(**Compiler.java:6322)  at 
>> clojure.lang.Compiler$**InvokeExpr.parse(Compiler.java**:3573)       at 
>> clojure.lang.Compiler.**analyzeSeq(Compiler.java:6562)       at 
>> clojure.lang.Compiler.analyze(**Compiler.java:6361)  at 
>> clojure.lang.Compiler.analyze(**Compiler.java:6322)  at 
>> clojure.lang.Compiler$**InvokeExpr.parse(Compiler.java**:3624)       at 
>> clojure.lang.Compiler.**analyzeSeq(Compiler.java:6562)       at 
>> clojure.lang.Compiler.analyze(**Compiler.java:6361)  at 
>> clojure.lang.Compiler.analyze(**Compiler.java:6322)  at 
>> clojure.lang.Compiler$**BodyExpr$Parser.parse(Compiler**.java:5708)  at 
>> clojure.lang.Compiler$**FnMethod.parse(Compiler.java:**5139) at 
>> clojure.lang.Compiler$FnExpr.**parse(Compiler.java:3751)     at 
>> clojure.lang.Compiler.**analyzeSeq(Compiler.java:6558)       at 
>> clojure.lang.Compiler.analyze(**Compiler.java:6361)  at 
>> clojure.lang.Compiler.**analyzeSeq(Compiler.java:6548)       at 
>> clojure.lang.Compiler.analyze(**Compiler.java:6361)  at 
>> clojure.lang.Compiler.access$**100(Compiler.java:37) at 
>> clojure.lang.Compiler$DefExpr$**Parser.parse(Compiler.java:529**)    at 
>> clojure.lang.Compiler.**analyzeSeq(Compiler.java:6560)       at 
>> clojure.lang.Compiler.analyze(**Compiler.java:6361)  at 
>> clojure.lang.Compiler.analyze(**Compiler.java:6322)  at 
>> clojure.lang.Compiler.eval(Com**piler.java:6623)     at 
>> clojure.lang.Compiler.load(Com**piler.java:7064)     at 
>> clojure.lang.RT.**loadResourceScript(RT.java:370**)  at 
>> clojure.lang.RT.**loadResourceScript(RT.java:361**)  at 
>> clojure.lang.RT.load(RT.java:**440)  at clojure.lang.RT.load(RT.java:**411)  
>> at clojure.core$load$fn__5018.**invoke(core.clj:5530)   at 
>> clojure.core$load.doInvoke(cor**e.clj:5529)  at 
>> clojure.lang.RestFn.invoke(Res**tFn.java:408)        at 
>> clojure.core$load_one.invoke(c**ore.clj:5336)        at 
>> clojure.core$load_lib$fn__**4967.invoke(core.clj:5375)       at 
>> clojure.core$load_lib.doInvoke**(core.clj:5374)      at 
>> clojure.lang.RestFn.applyTo(Re**stFn.java:142)       at 
>> clojure.core$apply.invoke(core**.clj:619)    at 
>> clojure.core$load_libs.**doInvoke(core.clj:5413)     at 
>> clojure.lang.RestFn.applyTo(Re**stFn.java:137)       at 
>> clojure.core$apply.invoke(core**.clj:619)    at 
>> clojure.core$require.doInvoke(**core.clj:5496)       at 
>> clojure.lang.RestFn.invoke(Res**tFn.java:408)        at 
>> user$eval3.invoke(NO_SOURCE_**FILE:1)        at 
>> clojure.lang.Compiler.eval(Com**piler.java:6619)     at 
>> clojure.lang.Compiler.eval(Com**piler.java:6608)     at 
>> clojure.lang.Compiler.eval(Com**piler.java:6582)     at 
>> clojure.core$eval.invoke(core.**clj:2852)    at 
>> clojure.main$eval_opt.invoke(m**ain.clj:308) at 
>> clojure.main$initialize.invoke**(main.clj:327)       at 
>> clojure.main$null_opt.invoke(m**ain.clj:362) at 
>> clojure.main$main.doInvoke(mai**n.clj:440)   at 
>> clojure.lang.RestFn.invoke(Res**tFn.java:421)        at 
>> clojure.lang.Var.invoke(Var.**java:419)      at 
>> clojure.lang.AFn.applyToHelper**(AFn.java:163)       at 
>> clojure.lang.Var.applyTo(Var.**java:532)     at 
>> clojure.main.main(main.java:37**)Caused by: java.lang.RuntimeException: No 
>> such namespace: hello     at 
>> clojure.lang.Util.**runtimeException(Util.java:219**)        at 
>> clojure.lang.Compiler.**resolveIn(Compiler.java:6844)        at 
>> clojure.lang.Compiler.resolve(**Compiler.java:6818)  at 
>> clojure.lang.Compiler.**analyzeSymbol(Compiler.java:**6779)  at 
>> clojure.lang.Compiler.analyze(**Compiler.java:6343)  ... 54 more)
>>
>>
>>
>>
>> -ramesh
>>
>  --
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to [email protected]
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to