environments and eval with user-defined library

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

environments and eval with user-defined library

Peter Lane
I've been using eval and environment as follows:

#|kawa:1|# (define env (environment '(srfi 1)))
#|kawa:2|# (environment-bound? env 'iota)
#t
#|kawa:3|# (eval '(iota 10) env)
(0 1 2 3 4 5 6 7 8 9)

Although this works for builtin libraries (like srfi 1), this does not
appear to work for my own libraries, e.g. below.  Notice on line two,
the symbol is bound in the environment, so (lib test) seems to be found
and loaded into 'env'. But during 'eval' there is no lib.test class found.

I'm running Kawa in r7rs mode, with the library in "./lib/test.sld":

$ kawa --r7rs -Dkawa.import.path="./*.sld"

Is this a limitation in the implementation?  Or do I need to give kawa
some more information?


#|kawa:1|# (define env (environment '(lib test)))
#|kawa:2|# (environment-bound? env 'test-me)
#t
#|kawa:3|# (eval '(test-me) env)
Exception in thread "main" java.lang.ExceptionInInitializerError
     at atEvalLevel-1.run(stdin:3)
     at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:293)
     at gnu.expr.ModuleExp.evalModule(ModuleExp.java:212)
     at kawa.lang.Eval.evalBody(Eval.java:100)
     at kawa.lang.Eval.evalForm$X(Eval.java:27)
     at kawa.lib.scheme.eval.eval$X(eval.scm:9)
     at atInteractiveLevel-3.run(stdin:3)
     at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:293)
     at gnu.expr.ModuleExp.evalModule(ModuleExp.java:212)
     at kawa.Shell.run(Shell.java:283)
     at kawa.Shell.run(Shell.java:196)
     at kawa.Shell.run(Shell.java:183)
     at kawa.repl.processArgs(repl.java:714)
     at kawa.repl.main(repl.java:820)
Caused by: java.lang.ClassNotFoundException: lib.test
     at gnu.mapping.WrappedException.rethrow(WrappedException.java:121)
     at gnu.expr.Compilation.setupLiterals(Compilation.java:2984)
     at lib.test.<clinit>(test.sld)
     ... 14 more
Caused by: java.lang.ClassNotFoundException: lib.test
     at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
     at gnu.bytecode.ArrayClassLoader.loadClass(ArrayClassLoader.java:132)
     at gnu.bytecode.ArrayClassLoader.loadClass(ArrayClassLoader.java:132)
     at gnu.expr.Compilation.setupLiterals(Compilation.java:2965)
     ... 15 more

--
Peter Lane
http://peterlane.info

Reply | Threaded
Open this post in threaded view
|

Re: environments and eval with user-defined library

Per Bothner
Sorry I almost forgot about this question.

On 02/18/2017 08:36 AM, Peter Lane wrote:
> I've been using eval and environment as follows:
>
> #|kawa:1|# (define env (environment '(srfi 1)))
> #|kawa:2|# (environment-bound? env 'iota)
> #t
> #|kawa:3|# (eval '(iota 10) env)
> (0 1 2 3 4 5 6 7 8 9)
>
> Although this works for builtin libraries (like srfi 1), this does not appear to work for my own libraries, e.g. below.

Could be a classpath issue.  Could also be this just doesn't work for
libraries loaded from source a compile on-the-fly,  That has
probably not been tested as much as one would like.

> Caused by: java.lang.ClassNotFoundException: lib.test
>     at gnu.mapping.WrappedException.rethrow(WrappedException.java:121)
>     at gnu.expr.Compilation.setupLiterals(Compilation.java:2984)
>     at lib.test.<clinit>(test.sld)
>     ... 14 more

Notice how the class lib.test is complaining that lib.test isn't found ...
Probably some ClassLoader not being set up right.
Possible a missing call to Compilation.usedClass.

If you can make a simple self-contained test-case I'll look into it.
--
        --Per Bothner
[hidden email]   http://per.bothner.com/