[I missed this discussion before now - due to some misconfiguration on my part.]
Doesn't Kawa Scheme have some kind of type declarations?
Yes. In most places where you can declare an identifier NAME
you can instead write NAME ::TYPE, which declared NAME to have the specified TYPE.
For example:
(let ((i ::integer (length '(A B C))))
(+ i i))
This declares the variable i to have type integer.
This is used both for error-checking and optimization.
That i has type integer, implies (among other things) that
it has an implementation type, in this case a reference
to the JVM class gnu.math.IntNum, which affects code generation.
It can enable various optimization. For example the + in the example
above is implemented as a call to the static method gnu.math.IntNum.add,
rather than generic addition.
The end result is that you can write Scheme code that is as efficient
as well-written Java, which can run run very fast indeed on modern JVMs.
(Kawa makes little use of the "newer" "invokedynamic" features, so far.)
Type-checking is done statically as "optimistic typing". Consider:
(let ((VARIABLE ::TYPE VALUE)) ...)
If the compiler can prove that VALUE is an instance of TYPE, no run-time code is needed.
In some cases, the type of VALUE may be semantically a subtype of TYPE,
but the implementation type is not a subtype of the implementation type of TYPE.
In that case, the compiler insert conversion code. For example of VALUE is
an (unboxed native 32-bit) 'int' but TYPE is 'integer' then the compiler inserts
a call to "box" the VALUE.
If the compiler can prove that the type of VALUE does not overlap with TYPE, then the compiler reports a compile-time error.
Otherwise, the compiler generates a run-time cast/type-check.
The compiler does some flow analysis that works pretty well,
thought it could be made more sophisticated. (It currently doesn't
make use of Scheme type prediacte such as integer?.) The type-system
is a bit ad hoc, but catches many error, allows very efficient code,
and is relatively "light" in use.
Type-testing is integrated with the pattern system:
(if (? NAME ::TYPE VALUE)
(do-this-if-TYPE NAME)
(do-this-if-not-TYPE))
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)