Unbound scheme procedures when calling from Java
Vladimir Tsichevski
wowa@jet.msk.su
Mon Mar 31 15:41:00 GMT 2003
Esko Nuutila wrote:
>We are trying to call our own Scheme procedures from Java. The
>problem is that only a part of the Scheme standard procedures seem to
>be bound. When using kawa interactively these procedures have correct
>bindings. The following files illustrate the problem:
>
>===small.scm===
>
>;;; Is reverse and append bound in the current environment?
>(define (test)
> (format #t "Reverse = ~S~%" reverse)
> (format #t "Append = ~S~%" append))
>
>===UseSmall.java===
>
>import kawa.standard.Scheme;
>
>public class UseSmall {
> public static void main(String[] args) {
> Scheme.registerEnvironment();
> small.test();
> }
>}
>
>===interactive run===
>
>
>
>>kawa
>>
>>
>#|kawa:1|# (load "small")
>#|kawa:2|# (test)
>Reverse = #<procedure reverse>
>Append = #<procedure append>
>#|kawa:3|#
>
>===Call from Java===
>
>
>
>>java UseSmall
>>
>>
>Reverse = #<procedure reverse>
>Exception in thread "main" java.lang.NullPointerException
> at small.test(small.scm:4)
> at UseSmall.main(UseSmall.java:6)
>
>====
>
>What can be the problem here? Is this the correct way to use Scheme
>from Java?
>
>Esko Nuutila
>
Hi,
I see small.test() in your code, so you implicitly suppose all methods
in small.scm are static. This is probably
not the case. Use (module-static #t) to force compilation of all module
procedures as static.
Here is what I got:
bash-2.05a$ cat small.scm
(module-static #t)
(define (test)
(format #t "Reverse = ~S~%" reverse)
(format #t "Append = ~S~%" append))
bash-2.05a$ cat UseSmall.java
import kawa.standard.Scheme;
public class UseSmall {
public static void main(String[] args) {
Scheme.registerEnvironment();
small.test();
}
}
bash-2.05a$ kawa -C small.scm
(compiling small.scm)
bash-2.05a$ javac UseSmall.java
bash-2.05a$ java UseSmall
Reverse = #<procedure reverse>
Append = #<procedure append>
Regards,
Vladimir
More information about the Kawa
mailing list