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
is a one-argument function that returns
T
?#t
if the argument is an instance of the type
,
and T
#f
otherwise:
(gnu.lists.FVector? #(123)) ⇒ #t (let ((iarr (int[] 10))) (int[]? iarr)) ⇒ #t
To convert (coerce) the result of an expression value
to a
type T
use the syntax: (->
.
T
value
)
(->float 12) ⇒ 12.0f0
In general:
(T
?x
) ⇒ (instance?x
T
) (->T
x
) ⇒ (asT
x
)
Procedure: instance?
value
type
Returns
#t
iffvalue
is an instance of typetype
. (Undefined iftype
is a primitive type, such asint
.)
Converts or coerces
value
to a value of typetype
. Throws an exception if that cannot be done. Not supported fortype
to be a primitive type such asint
.