Next: , Previous: , Up: Introspection   [Contents][Index]


8.8.2 Instances

primitive procedure: class-of value

Return the GOOPS class of any Scheme value.

primitive procedure: instance? object

Return #t if object is any GOOPS instance, otherwise #f.

procedure: is-a? object class

Return #t if object is an instance of class or one of its subclasses.

You can use the is-a? predicate to ask whether any given value belongs to a given class, or class-of to discover the class of a given value. Note that when GOOPS is loaded (by code using the (oop goops) module) built-in classes like <string>, <list> and <number> are automatically set up, corresponding to all Guile Scheme types.

(is-a? 2.3 <number>) ⇒ #t
(is-a? 2.3 <real>) ⇒ #t
(is-a? 2.3 <string>) ⇒ #f
(is-a? '("a" "b") <string>) ⇒ #f
(is-a? '("a" "b") <list>) ⇒ #t
(is-a? (car '("a" "b")) <string>) ⇒ #t
(is-a? <string> <class>) ⇒ #t
(is-a? <class> <string>) ⇒ #f

(class-of 2.3) ⇒ #<<class> <real> 908c708>
(class-of #(1 2 3)) ⇒ #<<class> <vector> 908cd20>
(class-of <string>) ⇒ #<<class> <class> 8bd3e10>
(class-of <class>) ⇒ #<<class> <class> 8bd3e10>