This is the mail archive of the
kawa@sources.redhat.com
mailing list for the Kawa project.
Re: More module problems
- To: "s.blomberg" <nhi965 at abdn dot ac dot uk>
- Subject: Re: More module problems
- From: Per Bothner <per at bothner dot com>
- Date: 24 Aug 2000 10:27:33 -0700
- Cc: Kawa Mailing List <kawa at sourceware dot cygnus dot com>
- References: <Pine.SOL.4.21.0008241756110.10602-100000@sysa.abdn.ac.uk>
"s.blomberg" <nhi965@abdn.ac.uk> writes:
> I compile it using the latest kawa release (just installed!), and I get 2
> files: Adder.class and Adder$Adder.class.
That doesn't sounds right. If you used the latest Kawa release (1.6.70),
you would not get 2 class files, only one Adder.class. Perhaps
Adder$Adder.class is lefter over from a previous time, or you are
actually using the old version of Kawa.
> I add these files to my Codewarrior project, plus the kawa 1.7
> .jar file.
You mean Kawa 1.6.70, I trust.
> public class TrivialApplication {
>
> public static void main(String args[]) {
> Adder test = new Adder();
> System.out.println( test.run( 5 ) );
> }
> }
>
> I noticed in the class browser that the method in the Adder class is
> called "run". (I don't understand why it is not called "Adder"?)
The "run" method contains the top-level code, including some initialization
code. However, in this simple case, run() actually does nothing.
> test.run(). I get the following error at compile-time:
>
> Error : Wrong number of arguments in method. TrivialApplication.java line
> 6 System.out.println( test.run( 5 ) );
Yep. Adder takes no arguments.
> This seems to disagree with the definition of the method Adder in the
> class file.
Note "run" != "Adder".
> Can anyone help me?
You need to do:
System.out.println( test.Adder( 5 ) );
or:
System.out.println( Adder.Adder( 5 ) );
since the Adder happens to be static.
However, I recommend making Adder a "static module" by adding
(module-static #t)
This makes all the compiled methods static, and causes any needed
initialization to be done in the class initializer - that way you
don't need to worry about it:
public static void main(String args[]) {
System.out.println( Adder.Adder( new gnu.math.IntNum(5) ) );
}
}
Note that Adder takes an Object, not an int, hence the need for the IntNum.
Alternatively, you can write the definition of Adder as:
(define (Adder (x :: <int>)) <int> (+ 5 x))
That specifies that the argument and returns types are int, not an Object.
--
--Per Bothner
per@bothner.com http://www.bothner.com/~per/