Type tests and conversions

Scheme defines a number of standard type testing predicates. For example (vector? x) is #t if and only if x is a vector.

Kawa generalizes this to arbitrary type names: If T is a type-name (that is in scope at compile-time), then T? is a one-argument function that returns #t if the argument is an instance of the type T, and #f otherwise:

(gnu.lists.FVector? #(123)) ⇒ #t
(let ((iarr (int[] 10))) (int[]? iarr)) ⇒ #t 

In general:

(T? x) ⇒ (instance? x T)

Procedure: instance? value type

Returns #t iff value is an instance of type type. (Undefined if type is a primitive type, such as int.)

Procedure: as type value

Converts or coerces value to a value of type type. Throws an exception if that cannot be done. Not supported for type to be a primitive type such as <int>.