Module imports lead to method signature errors?
Norman Gray <[email protected]> Fri, 12 Dec 2008 12:27:23 +0000
| Newsgroups | gmane.comp.java.sisc.user |
|---|---|
| Message-ID | <[email protected]> |
Greetings.
I appear to have found a situation in which a definition of a symbol
inside a module appear to be disrupting definitions of the same symbol
elsewhere. If this is indeed a bug -- as opposed to me being confused
about something -- I'll put it on the sourceforge tracker.
Consider the following:
%% cat MyWriter.java
public class MyWriter {
public void write(java.io.OutputStream w, int x) {
System.out.println(x);
}
public void write(java.io.Writer w, int x) {
System.out.println(x);
}
}
%% javac MyWriter.java
%% cat s2j-module.scm
(import s2j)
(module s2j-module
(s2j-test)
(define-java-classes
<my-writer>
;<com.hp.hpl.jena.rdf.model.model> ; where the problem originally
appeared
)
(define (s2j-test)
#f))
%% cat test-s2j-module.scm
(require-library 's2j-module)
(import s2j-module)
(format #t "test-s2j-module~%")
%% cat test-write.scm
(import s2j)
(define system-out
((generic-java-field-accessor 'out) (java-null (java-class '|
java.lang.System|))))
(define-java-classes <java.io.output-stream-writer>)
(define-generic-java-methods write flush)
(let ((writer (java-new <java.io.output-stream-writer> system-out)))
(write writer (->jstring "Wibble\n"))
(flush writer))
%% sisc
SISC (1.16.6)
#;> (load "test-write.scm")
Wibble
#;> ^D
%% sisc
SISC (1.16.6)
#;> (load "test-s2j-module.scm")
test-s2j-module
#;> (load "test-write.scm")
Error in load: evaluation error at file:/checkouts/agast/repositories/
qadi/code/qadi/src/test/scm/reduction/test-write.scm:7:1
---------------------------
To enable more detailed stack tracing, set the dynamic parameter max-
stack-trace-depth to a non-zero value, e.g. 16.
---------------------------
Some stack trace entries may have been suppressed. To see all entries
set the dynamic parameter suppressed-stack-trace-source-kinds to '().
===========================
Caused by Error: no applicable method for args (#<java
java.io.OutputStreamWriter java.io.OutputStreamWriter@7aa93a16> #<java
java.lang.String Wibble
>) in generic procedure #0=#<procedure write>
file:/checkouts/agast/repositories/qadi/code/qadi/src/test/scm/
reduction/test-write.scm:8:3: <indeterminate call>
#;> ^D
%%
The s2j-module.scm file declares a module s2j-module, and defines a
Java class, namely MyWriter; this class has a number of write(...)
methods (it appears to require more than one method to be present).
The test-s2j-module.scm file simply imports this s2j-module module.
test-write.scm writes a string to System.out using the
Writer.write(String) method. Run by itself, test-write.scm works.
When run after test-s2j-module.scm, however, the same call to
Writer.write(String) fails. I can't see why that would be happening.
On a separate matter, which _may_ be related:
I'm slightly unsure of the semantics of LOAD. When I do the
following, aiming to explicitly isolate modules from each other:
%% sisc
SISC (1.16.6)
#;> (define (my-load file)
(let ((load-env (make-child-environment (interaction-environment))))
(with-input-from-file file
(lambda ()
(let loop ((sexp (read)))
(unless (eof-object? sexp)
(eval sexp load-env)
(loop (read))))))))
#;> (my-load "test-s2j-module.scm")
test-s2j-module
#;> (my-load "test-write.scm")
Error: no applicable method for args (#<java
java.io.OutputStreamWriter java.io.OutputStreamWriter@6dabd6b0> #<java
java.lang.String Wibble
>) in generic procedure #0=#<procedure write>
console:7:19: <indeterminate call>
---------------------------
To enable more detailed stack tracing, set the dynamic parameter max-
stack-trace-depth to a non-zero value, e.g. 16.
---------------------------
Some stack trace entries may have been suppressed. To see all entries
set the dynamic parameter suppressed-stack-trace-source-kinds to '().
#;>
...I get the same effect. So, I think, LOAD is doing the same thing
as MY-LOAD.
In the real regression test (which fails in the same way as the
reduction above), when I replace the LOAD in that case with MY-LOAD as
defined above, I get a _different_ failure, with an error:
[java] sisc.interpreter.SchemeException: ((message . "import
from unknown module srfi-8"))
[java] at
sisc.interpreter.SchemeRuntimeException.promote(Unknown Source)
[java] at sisc.interpreter.Interpreter.interpret(Unknown Source)
[java] at sisc.interpreter.Interpreter.interpret(Unknown Source)
[java] at sisc.interpreter.Interpreter.eval(Unknown Source)
[java] at sisc.REPL.main(Unknown Source)
That appears when loading a module which starts
(import s2j)
(require-library 'util/decode-der)
(require-library 'util/lambda-contract)
(require-library 'quaestor/jena)
(require-library 'quaestor/utils)
(require-library 'sisc/libs/srfi/srfi-1) ; lists
(require-library 'sisc/libs/srfi/srfi-8) ; receive
(module x509-certificates
....
So it's not even the first require-library that it's failing on.
I'm now confused! Any comments would be most welcome.
Best wishes,
Norman
--
Norman Gray : http://nxg.me.uk
Dept Physics and Astronomy, University of Leicester
------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you. Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/