Outdated egg!

This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 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.

Tinyclos-xerox

A very simple CLOS-like language, embedded in Scheme, with a simple MOP.

Documentation

NOTE: Chicken is normally case-sensitive, and constructs depicted below in upper case for the purposes of exposition should be expressed in lower case during use.

     

The features of the default base TinyCLOS language are:

 * Classes, with instance slots, but no slot options.
 * Multiple-inheritance.
 * Generic functions with multi-methods and class specializers only.
 * Primary methods and call-next-method; no other method combination.
 * Uses Scheme's lexical scoping facilities as the class and generic
   function naming mechanism.  Another way of saying this is that
   class, generic function and methods are first-class (meta)objects.

While the MOP is simple, it is essentially equal in power to both MOPs in AMOP. This implementation is not at all optimized, but the MOP is designed so that it can be optimized. In fact, this MOP allows better optimization of slot access extenstions than those in AMOP.

In addition to calling a generic, the entry points to the default base language are:

 (MAKE-CLASS list-of-superclasses list-of-slot-names)
 (MAKE-GENERIC)
 (MAKE-METHOD list-of-specializers procedure)
 (ADD-METHOD generic method)
 (MAKE class . initargs)
 (INITIALIZE instance initargs)            ;Add methods to this, don't call it directly.
 (SLOT-REF  object slot-name)
 (SLOT-SET! object slot-name new-value)

So, for example, one might do:

 (define  (make-class (list ) (list 'x 'y)))
 (add-method initialize
     (make-method (list )
       (lambda (call-next-method pos initargs)
         (for-each (lambda (initarg-name slot-name)
                     (slot-set! pos
                                slot-name
                                (getl initargs initarg-name 0)))
                   '(x y)
                   '(x y)))))
 (set! p1 (make  'x 1 'y 3))

NOTE! Do not use EQUAL? to compare objects! Use EQ? or some hand written procedure. Objects have a pointer to their class, and classes are circular structures, and ...

The introspective part of the MOP looks like the following. Note that these are ordinary procedures, not generics.

 CLASS-DIRECT-SUPERS
 CLASS-DIRECT-SLOTS
 CLASS-CPL
 CLASS-SLOTS
 GENERIC-METHODS
 METHOD-SPECIALIZERS
 METHOD-PROCEDURE

The intercessory protocol looks like (generics in uppercase):

 make                        
   ALLOCATE-INSTANCE
   INITIALIZE                   (really a base-level generic)
 class initialization
   COMPUTE-CPL
   COMPUTE-SLOTS
   COMPUTE-GETTER-AND-SETTER
 add-method                     (Notice this is not a generic!)
   COMPUTE-APPLY-GENERIC
     COMPUTE-METHODS
       COMPUTE-METHOD-MORE-SPECIFIC?
     COMPUTE-APPLY-METHODS

As for the low-level memory system, assume the existence of:

%allocate-instance (nfields)
%instance-ref      (instance field-number)
%instance-set!     (instance field-number new)
%allocate-entity   (nfields)
%entity-ref        (instance field-number)
%entity-set!       (instance field-number new)
class-of           (any-object)

License

 **********************************************************************
 Copyright (c) 1992 Xerox Corporation.  
 All Rights Reserved.  
 
 Use, reproduction, and preparation of derivative works are permitted.
 Any copy of this software or of any derivative work must include the
 above copyright notice of Xerox Corporation, this paragraph and the
 one after it.  Any distribution of this software or derivative works
 must comply with all applicable United States export control laws.
 
 This software is made available AS IS, and XEROX CORPORATION DISCLAIMS
 ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE
 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 PURPOSE, AND NOTWITHSTANDING ANY OTHER PROVISION CONTAINED HEREIN, ANY
 LIABILITY FOR DAMAGES RESULTING FROM THE SOFTWARE OR ITS USE IS
 EXPRESSLY DISCLAIMED, WHETHER ARISING IN CONTRACT, TORT (INCLUDING
 NEGLIGENCE) OR STRICT LIABILITY, EVEN IF XEROX CORPORATION IS ADVISED
 OF THE POSSIBILITY OF SUCH DAMAGES.
 **********************************************************************

Edit history