This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: case-lambda and Java


On Dec 13, 2009, at 11:14 PM, Per Bothner wrote:

On 12/08/2009 09:10 AM, Jamison Hope wrote:
On Dec 7, 2009, at 7:02 PM, Per Bothner wrote:
(define-constant ->list :: procedure
(case-lambda ...))

Then $Mn$Grlist will have type gnu.mapping.Procedure, which
means you can use Procedure's various apply* methods.

I just fixed a bug where define-constant would cause the generated field to have the FINAL property - even when it is assigned to in the "run" method (as in this case, unless you're compiling with --module-static-run). Surprised this wasn't caught earlier ...

When I define ->list like this:
(define-constant ->list :: procedure
(case-lambda ...))
then javap does report $Mn$Grlist as a Procedure
public static final gnu.mapping.Procedure $Mn$Grlist;

but I can't actually use it. In Scheme, if I attempt to compile a file
which does nothing but
(require collections_utils)

-- I'm not even trying to invoke the function yet -- I get a compilation
error:
$ java kawa.repl --target 1.5 --module-static-run
--warn-undefined-variable --main -C usage1.scm
(compiling usage1.scm to usage1)
internal error while compiling usage1.scm
java.lang.ExceptionInInitializerError

Hm. I'm not seeing this. Perhaps you double-check,and then resend the files (as attachments) and instructions and I can take a look.

OK, here you go. collections_utils.scm defines four variations of the - >list function, exactly one of which must be uncommented at a time; because they affect the resultant Java type of $Mn$Grlist, there are corresponding statements in Usage2.java which must be commented/ uncommented as appropriate. You should also comment out the indicated line in usage1.scm to verify that compilation can fail with just the 'require. I'm sending it to you configured for the variation which I got to work (labeled #1).


To compile and run the two tests (the first is with the Scheme client, usage1.scm, and the second is with the Java client, Usage2.java):

make clean
make run1
make run2

With a vanilla kawa-1.9.90.jar, here's what I get when I try each of the four cases:


#1 ("define" without type declaration):


$ make clean
rm -f *.class
$ make run1
java kawa.repl --target 1.5 --module-static-run --warn-undefined- variable -C collections_utils.scm
(compiling collections_utils.scm to collections_utils)
java kawa.repl --target 1.5 --module-static-run --warn-undefined- variable --main -C usage1.scm
(compiling usage1.scm to usage1)
java usage1
(1 2 3 4 5)
$ make run2
javac Usage2.java
java Usage2
(1 2 3 4 5)



#2 ("define" with type declaration):


$ make clean
rm -f *.class
$ make run1
java kawa.repl --target 1.5 --module-static-run --warn-undefined- variable -C collections_utils.scm
(compiling collections_utils.scm to collections_utils)
java kawa.repl --target 1.5 --module-static-run --warn-undefined- variable --main -C usage1.scm
(compiling usage1.scm to usage1)
internal error while compiling usage1.scm
java.lang.NullPointerException
at gnu.expr.ScopeExp.lookup(ScopeExp.java:166)
at kawa.standard.require.importDefinitions(require.java:369)
at kawa.standard.require.scanForDefinitions(require.java:201)
at kawa.lang.Syntax.scanForm(Syntax.java:65)
at kawa.lang.Translator.scanForm(Translator.java:1054)
at gnu.kawa.lispexpr.LispLanguage.parse(LispLanguage.java:57)
at gnu.expr.Compilation.process(Compilation.java:1858)
at gnu.expr.ModuleInfo.loadByStages(ModuleInfo.java:308)
at gnu.expr.ModuleInfo.loadByStages(ModuleInfo.java:293)
at gnu.expr.ModuleInfo.loadByStages(ModuleInfo.java:293)
at gnu.expr.ModuleInfo.loadByStages(ModuleInfo.java:293)
at gnu.expr.ModuleInfo.loadByStages(ModuleInfo.java:293)
at gnu.expr.ModuleInfo.loadByStages(ModuleInfo.java:293)
at kawa.repl.compileFiles(repl.java:803)
at kawa.repl.processArgs(repl.java:457)
at kawa.repl.main(repl.java:866)
make: *** [usage1.class] Error 255
$ make run2
javac Usage2.java
java Usage2
(1 2 3 4 5)



#3 ("define-constant" with type declaration):


$ make clean
rm -f *.class
$ make run1
java kawa.repl --target 1.5 --module-static-run --warn-undefined- variable -C collections_utils.scm
(compiling collections_utils.scm to collections_utils)
java kawa.repl --target 1.5 --module-static-run --warn-undefined- variable --main -C usage1.scm
(compiling usage1.scm to usage1)
internal error while compiling usage1.scm
java.lang.ExceptionInInitializerError
at sun.misc.Unsafe.ensureClassInitialized(Native Method)
at sun .reflect .UnsafeFieldAccessorFactory .newFieldAccessor(UnsafeFieldAccessorFactory.java:25)
at sun.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java: 122)
at java.lang.reflect.Field.acquireFieldAccessor(Field.java:918)
at java.lang.reflect.Field.getFieldAccessor(Field.java:899)
at java.lang.reflect.Field.get(Field.java:358)
at gnu.expr.ModuleInfo.setupModuleExp(ModuleInfo.java:167)
at kawa.standard.require.importDefinitions(require.java:292)
at kawa.standard.require.scanForDefinitions(require.java:201)
at kawa.lang.Syntax.scanForm(Syntax.java:65)
at kawa.lang.Translator.scanForm(Translator.java:1054)
at gnu.kawa.lispexpr.LispLanguage.parse(LispLanguage.java:57)
at gnu.expr.Compilation.process(Compilation.java:1858)
at gnu.expr.ModuleInfo.loadByStages(ModuleInfo.java:308)
at gnu.expr.ModuleInfo.loadByStages(ModuleInfo.java:293)
at gnu.expr.ModuleInfo.loadByStages(ModuleInfo.java:293)
at gnu.expr.ModuleInfo.loadByStages(ModuleInfo.java:293)
at gnu.expr.ModuleInfo.loadByStages(ModuleInfo.java:293)
at gnu.expr.ModuleInfo.loadByStages(ModuleInfo.java:293)
at kawa.repl.compileFiles(repl.java:803)
at kawa.repl.processArgs(repl.java:457)
at kawa.repl.main(repl.java:866)
Caused by: java.lang.NullPointerException
at gnu.expr.GenericProc.add(GenericProc.java:62)
at gnu.expr.GenericProc.setProperties(GenericProc.java:273)
at gnu.expr.GenericProc.make(GenericProc.java:281)
at gnu.kawa.functions.MakeProcedure.applyN(MakeProcedure.java:17)
at collections_utils.<clinit>(collections_utils.scm:65)
... 22 more
make: *** [usage1.class] Error 255
$ make run2
javac Usage2.java
java Usage2
java.lang.ExceptionInInitializerError
at Usage2.main(Usage2.java:27)
Caused by: java.lang.NullPointerException
at gnu.expr.GenericProc.add(GenericProc.java:62)
at gnu.expr.GenericProc.setProperties(GenericProc.java:273)
at gnu.expr.GenericProc.make(GenericProc.java:281)
at gnu.kawa.functions.MakeProcedure.applyN(MakeProcedure.java:17)
at collections_utils.<clinit>(collections_utils.scm:65)
... 1 more



#4 ("define-constant" without type declaration):
$ make clean
rm -f *.class
$ make run1
java kawa.repl --target 1.5 --module-static-run --warn-undefined- variable -C collections_utils.scm
(compiling collections_utils.scm to collections_utils)
java kawa.repl --target 1.5 --module-static-run --warn-undefined- variable --main -C usage1.scm
(compiling usage1.scm to usage1)
internal error while compiling usage1.scm
java.lang.ExceptionInInitializerError
at sun.misc.Unsafe.ensureClassInitialized(Native Method)
at sun .reflect .UnsafeFieldAccessorFactory .newFieldAccessor(UnsafeFieldAccessorFactory.java:25)
at sun.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java: 122)
at java.lang.reflect.Field.acquireFieldAccessor(Field.java:918)
at java.lang.reflect.Field.getFieldAccessor(Field.java:899)
at java.lang.reflect.Field.get(Field.java:358)
at gnu.expr.ModuleInfo.setupModuleExp(ModuleInfo.java:167)
at kawa.standard.require.importDefinitions(require.java:292)
at kawa.standard.require.scanForDefinitions(require.java:201)
at kawa.lang.Syntax.scanForm(Syntax.java:65)
at kawa.lang.Translator.scanForm(Translator.java:1054)
at gnu.kawa.lispexpr.LispLanguage.parse(LispLanguage.java:57)
at gnu.expr.Compilation.process(Compilation.java:1858)
at gnu.expr.ModuleInfo.loadByStages(ModuleInfo.java:308)
at gnu.expr.ModuleInfo.loadByStages(ModuleInfo.java:293)
at gnu.expr.ModuleInfo.loadByStages(ModuleInfo.java:293)
at gnu.expr.ModuleInfo.loadByStages(ModuleInfo.java:293)
at gnu.expr.ModuleInfo.loadByStages(ModuleInfo.java:293)
at gnu.expr.ModuleInfo.loadByStages(ModuleInfo.java:293)
at kawa.repl.compileFiles(repl.java:803)
at kawa.repl.processArgs(repl.java:457)
at kawa.repl.main(repl.java:866)
Caused by: java.lang.NullPointerException
at gnu.expr.GenericProc.add(GenericProc.java:62)
at gnu.expr.GenericProc.setProperties(GenericProc.java:273)
at gnu.expr.GenericProc.make(GenericProc.java:281)
at gnu.kawa.functions.MakeProcedure.applyN(MakeProcedure.java:17)
at collections_utils.<clinit>(collections_utils.scm:74)
... 22 more
make: *** [usage1.class] Error 255
$ make run2
javac Usage2.java
java Usage2
java.lang.ExceptionInInitializerError
at Usage2.main(Usage2.java:31)
Caused by: java.lang.NullPointerException
at gnu.expr.GenericProc.add(GenericProc.java:62)
at gnu.expr.GenericProc.setProperties(GenericProc.java:273)
at gnu.expr.GenericProc.make(GenericProc.java:281)
at gnu.kawa.functions.MakeProcedure.applyN(MakeProcedure.java:17)
at collections_utils.<clinit>(collections_utils.scm:74)
... 1 more



-- Jamison Hope The PTR Group www.theptrgroup.com


Attachment: kawa_case_lambda_test.tbz
Description: Binary data


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]