Previous: Parameterized Types, Up: Types [Contents][Index]
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
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) ⇒ (as T x)
Returns #t iff value is an instance of type type.
(Undefined if type is a primitive type, such as int.)
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.
Previous: Parameterized Types, Up: Types [Contents][Index]