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
- 10/**/92 Gregor Originally Written
- 1.0 11/10/92 Gregor Changed names of generic invocation generics. Changed compute-getters-and-setters protocol. Made comments match the code. Changed maximum line width to 72.
- 1.1 11/24/92 Gregor Heavily edited to produce the reflective RPP processor program that is actually running. This is intended to be a tool for discussing what the language and protocol should be. In the process of doing this, several small bugs were discovered, see the tiny-clos.scm file.
- 1.2 12/02/92 Gregor See tiny-clos.scm.
- 1.3 12/08/92 Gregor See tiny-clos.scm.