java 11
Per Bothner
per@bothner.com
Mon Dec 3 01:50:00 GMT 2018
On 12/2/18 3:00 PM, daniel szmulewicz wrote:
> Hi,
>
> I wrote my first Kawa script, yay!
> I wanted to explore Java interop, so the following script does a http
> request with the new HttpClient that ships in Java 11. However, as you can
> see, some methods needed to be fully qualified in order to make it work. Is
> this a case of reflection not working with the new Java modules? Am I
> missing something? Thank you!
Works for me (using openjdk 11.0.1).
Your problem may be that you're running the script using load,
or using the -f command-line flag. That reads, compiles, and evaluates
each line one-by-one which is undesirable for a number of reasons.
For one it hurts various optimizations and requires more reflection.
Instead run the script directly from the command line:
$ kawa my-script.scm
(without using the -f option).
If using the REPL, you can use require instead of load:
$ kawa
#|kawa:3|# (require "my-script.scm")
Note that "load" is a procedure that reads the file line-by-line,
while "require" is syntax (a macro) that reads the file at "compile-time".
It will also work better (no warnings) if you stick to using
the CLASS_NAME:METHOD_NAME syntax for static methods. For instance methods
we prefer INSTANCE:METHOD_NAME.
Specifically, replace the last two lines by:
(define response (client:send request body-handler))
(display (response:body))
--
--Per Bothner
per@bothner.com http://per.bothner.com/
More information about the Kawa
mailing list