|[ < ]||[ > ]||[ << ]||[ Up ]||[ >> ]||[Top]||[Contents]||[Index]||[ ? ]|
Scheme is a dynamically and strongly typed language. That is, every value knows its type at run-time, and the type determines what kind of operations can be applied on the value.
In Gauche, classes are used to describe types. A class is also an object you can handle at runtime. You can also create a new class in order to have objects with distinct types.
In this section we introduce the most basic interface to the Gauche’s type system. See section Object system, for the details of how to define your own classes and creates values (instances).
Predefined classes are bound to a global variable; Gauche’s
convention is to name the variable that holds a class
(It’s nothing syntactically special with these brackets; they’re valid
characters to consist of variable names).
We’ll introduce classes for each built-in type as we go through
this chapter. Here are a few basic classes to start with:
This class represents the supertype of all the types in Gauche.
That is, for any class
(subtype? X <top>) is
and for any object
(is-a? x <top>) is
This class represents the subtype of all the types in Gauche.
For any class
(subtype? <bottom> X) is
and for any object
(is-a? x <bottom>) is
This class represents a supertype of all user-defined classes.
Returns a class metaobject of obj.
(class-of 3) ⇒ #<class <integer>> (class-of "foo") ⇒ #<class <string>> (class-of <integer>) ⇒ #<class <class>>
Note: In Gauche, you can redefine exsting user-defined classes.
If the new definition has different configuration of the instance,
class-of on existing instance triggers instance updates;
See section Class redefinition for the details. Using
current-class-of supresses instance updates
(See section Accessing instance).
Returns true if obj is an instance of class or an instance of descendants of class.
(is-a? 3 <integer>) ⇒ #t (is-a? 3 <real>) ⇒ #t (is-a? 5+3i <real>) ⇒ #f (is-a? :foo <symbol>) ⇒ #f
Note: If obj’s class has been redefined,
triggers instance update.
See Class redefinition for the details.
#t if a class sub is a subclass of a class super
(includes the case that sub is super).
subtype? is taken from Common Lisp’s procedure
|[ < ]||[ > ]||[ << ]||[ Up ]||[ >> ]|
This document was generated by Shiro Kawai on May 28, 2012 using texi2html 1.82.