What is the equivalent of Java import?
Kawa's import
follows R6RS, so it is bit like
Java's import static TypeName.*
(static-import-on-demand) declaration.
Kawa doesn't have a direct equivalent of
Java's import TypeName
(single-type-import) declaration,
but define-alias
provides similar functionality:
(define-alias StrBuf java.lang.StringBuffer)
This has the advantage that you can pick an arbitrary name as an alias.
There is no direct equivalent to Java's import PackageOrTypeName.*
(type-import-on-demand) declaration, but you can alias a package:
(define-alias jutil java.util) (define mylist :: jutil:List (jutil:ArrayList))
You can also use define-namespace
to introduce an abbreviation or
renaming of a class name, but as a matter of style define-alias
is preferred.
How do I refer to a Java member (nested) class?
Consider the Java SE member class javax.swing.text.AbstractDocument.Content
.
Using the Java syntax doesn't work in Kawa.
Inside you should use Kawa's colon operator:
javax.swing.text.AbstractDocument:Content
Alternatively, you can use the internal JVM class name:
javax.swing.text.AbstractDocument$Content
Why does Kawa's REPL use display rather than write?
The read-eval-print-loop of most Scheme implementations prints the
evaluation result using write
, while Kawa uses display
by default.
First note that it is easy to override the default with the
--output-format
command-line option:
$kawa --output-format readable-scheme #|kawa:1|# "abc" "abc"
The reason display
is the default is because of a vision of the REPL
console as more than just printing out Scheme objects in
textual form for use by a programmer.
Some examples:
A math program can display equations and graphs as the output of an expression.
An expression can evaluate to a "picture" which would be displayed inline.
An HTML/XML obj can be insert into the output in visual form if the console understands HTML. (There is a prototype for this that works by using the JavaFX WebView as the display.)
The plan for "Kawa-shell" functionality is to have expressions that evaluate to process objects, which would be lazy strings. This string would be the data from standard output. Thus the effect of displaying a process object would be to print out the standard output - just like a regular shell. Users would find it confusing/annoying if shell output used quotes.
This "repl-as-pad" model doesn't work as well if the repl
uses write
rather than display
.