Outdated egg!

This is an egg for CHICKEN 3, the unsupported old release. You're almost certainly looking for the CHICKEN 4 version of this egg, if it exists.

If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.

  1. Outdated egg!
  2. POS
    1. Introduction
    2. Requirements
    3. Documentation
      1. Class Definition
        1. class-variables
        2. instance-variables
        3. class-methods
          1. Built-in class methods
        4. instance-methods
          1. Built-in instance methods
    4. License
    5. Author
    6. History

POS

Introduction

POS is a portable object system for Scheme.

Requirements

An implementation of syntax-rules (syntax-case, syntactic-closures or alexpander)

Documentation

POS offers the following features:

Class Definition

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:

class-variables

a list of class variables with initial values (in let format). The cvars is a required literal.

Example:

{{(cvars (a 1) (b 2))}}
instance-variables

a list of instance variables with initial values (in let format). The ivars is a required literal.

Example:

{{(ivars (c 3) (d 4))}}
class-methods

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 ...)
Built-in class methods
'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)
instance-methods

have the same format as class-methods except that the literal imeths is used.

Built-in instance methods
'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.

License

Copyright (c) 2006 Blake McBride (blake@mcbride.name)
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.

Author

Blake McBride (blake(at)mcbride(dot)name)

History

1.0
Initial release