home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-01-10 | 4.3 KB | 119 lines | [TEXT/EDIT] |
- ; ............ A SCOOPS OBJECT SYSTEM IN MACSCHEME: README.DOC ............
- ;
- ;
- ;The included code was prepared by John Ulrich and is distributed by Semantic
- ;Microsystems as a service to the Scheme community. You may copy, modify,
- ;and distribute it provided you include this notice in any copy or modified
- ;copy. This code should not be regarded as any sort of endorsement of SCOOPS
- ;as an object system for Scheme. Semantic intends to support a Scheme
- ;object system standard if and when one is adopted by the Scheme committee.
- ;
- ;SCOOPS was originally specified and implemented by Texas Instruments for
- ;PCScheme. By implementing SCOOPS in MacScheme I hope to help those who
- ;are porting code between the two Scheme dialects. I have attempted to
- ;follow the specification as given in the PCScheme manual; however, there
- ;will likely be some subtle differences. Any discovered differences between
- ;the PCScheme and the MacScheme implementations should be brought to my
- ;attention.
-
- ;For those familiar with SCOOPS, files readme.doc and examples.sch
- ;will get you started. Those unfamiliar with SCOOPS should also read
- ;the TI documentation found in scoops.doc.part1 and scoops.doc.part2.
- ;
- ;
- ;
- ; John Ulrich
- ; P.O. 1636
- ; Beaverton
- ; OR 97075
- ;
- ; November,1987
- ;
- ;
- ;the first example illustrates classvars, instvars, set and get methods.
- (define-class location
- (classvars (w 'baker)(u 'able))
- (instvars (x 400)
- (y (active 500 (lambda (x)(display "get method ") x)
- (lambda (x)(display "set method ") x))))
- (options gettable-variables settable-variables inittable-variables))
-
- ;the next example illustrates inheritance. Order is important. Location
- ;must be defined before support since support inherits from location.
- ;Location may be later redefined and support will be automatically
- ;updated.
-
- (define-class support
- (instvars (price 0)(material 'wood))
- (mixins location)
- (options gettable-variables settable-variables inittable-variables))
-
-
- ;The next two examples illustrate two classes with a common
- ;lexical environment. Because chairs mixin furniture and support methods
- ;and a furniture method refers to the bound variable lex, chairs must
- ;be defined in the same environment as furniture. No error will be detected
- ;it this is violated, but in this case, the variable lex refered to in
- ;chair will be distinct from the variable lex refered to in furniture.
-
- (let ((lex 'baz))
- ;This example shows how to define instance methods.
- (define-class furniture
- (instvars (price 0) (purpose 'sitting))
- (methods (print-lex (lambda ()(display lex)(newline)))
- (move (lambda (deltax deltay)
- (set! x (+ x deltax))
- (set! y (+ y deltay))
- ))
- (set-lex (lambda(x)(set! lex x))))
- (mixins location)
- (options gettable-variables settable-variables inittable-variables))
-
- ;In the following, the important point is that material is not settable
- ;in a chair even though it is settable in support and chair
- ;inherits from support. The reason is that material in chair shadows
- ;material in support and material is excluded from the settable variables
- ;in the definition of chair.
-
-
- (define-class chair
- (instvars (number-of-legs 4)(material 'metal))
- (mixins furniture support)
- (options gettable-variables
- (settable-variables number-of-legs)
- inittable-variables)))
-
-
- ;sanity checks
- (all-classvars chair)
- (all-instvars chair)
- (all-methods chair)
- (class-compiled? chair)
- (set! ch1 (make-instance chair 'x 500 'y 500))
- (class-of-object ch1)
- (classvars chair)
- (compile-class chair)
- (describe chair)
- (getcv chair u)
- (setcv chair u 'able)
- (getcv chair u)
- (instvars chair)
- (methods chair)
- (mixins chair)
- (name->class 'chair)
- (rename-class (chair newchair))
- (name->class 'newchair)
- (send-if-handles ch1 foo)
- (send ch1 set-y 500)
- (define-method (location row)
- (z)(+ x y z))
- (all-methods chair)
- ;there will be a long pause while chair is recompiled
- (set! ch2 (make-instance chair))
- (send ch2 row 5)
- (send ch2 set-x 40)
- (send ch2 set-y 50)
- (send ch2 row 10)
- (compile-class chair)
-
-