Note: This is taken from the Chicken Wiki, where a more recent version could be available.
POS is a portable object system for Scheme.
POS offers the following features:
Classes are defined with a single macro as follows:
(define-class class-name [class-defn-clause] ...)
class-name is the name of the new class (as a symbol), e.g. myclass
class-defn-clause consists of any combination of class definition clauses in any order. The following lists the various types available:
a list of class variables with initial values (in let format). The cvars is a required literal.
(cvars (a 1) (b 2))
a list of instance variables with initial values (in let format). The ivars is a required literal.
(ivars (c 3) (d 4))
a list of class method definitions in the format: The cmeths is a required literal.
(cmeths meth1 meth2 ...)
where each meth looks as follows:
(meth-name (self arg1 arg2 ...) code ...)
'name ;; returns the string name of the class 'super 'meth arg1 ... ;; executes a super-method (meth) 'class ;; return #f (so you know you have a class object)
have the same format as class-methods except that the literal imeths is used.
'class ;; returns the class object of the instance 'super 'meth arg1 ... ;; executes a super-method (meth)
Instance variables defined in the class where the instance method is defined are accessible (set or get) as any other local variable.
Class variables defined in the class where the class method is defined are accessible (set or get) as any other local variable. Class methods and class variables work analogously to their instance counter parts as they should (contrary to Java).
self can be used as in other OO languages. 'self' in class methods refers to the class object.
Execution of methods on an object (class or instance):
(object 'method arg1 arg2 ...)
Creation of new instances can occur in two ways. The first way is to use use the primitive function "make" as follows:
(define ins (make <myclass>))
This creates an instance of the <myclass> class with all instance variables set to their default values and no special processing.
The other way is to create a class method which takes potential arguments, creates a new instance, and performs any additional initialization processes. See example-02.scm for an example of this.
Note that the <> around class names is just a convention and not necessary.
Copyright (c) 2006 Blake McBride (email@example.com) All rights reserved. Free for any use so long as this note remains intact. No warranty of any kind either express or implied. Use at your own risk.
Blake McBride (blake(at)mcbride(dot)name)