SELF: Another OO-Framework for Scheme?
SELF: Another OO-Framework for Scheme?
Test it. Download self.tgz. Load self.scm and take a look at rope.scm.

Define a class rope with n slots and a slot for current length.

(define-slotted-class 'rope          ;; class name
                      '((length 0))  ;; a additional slot
                      '(slotted))    ;; super classes: slotted
Defining a method, here the new and its initmethod:
(define-method rope new args
  (apply init self args))

(define-method rope init (init-size)
  (oos!simple-clone self (+ 1 init-size)))
A pretty show-on method produces rope[0-2] for a rope of length 2:
(define-method rope show-on (a-port)
  (display (class-name self) a-port)
  (display "[0-" a-port)
  (display (size self))
  (display "]" a-port))
Defining a iterator:
(define-method rope for-elements (do-proc)
  (let ((l (size self))
	(i 0))
    (while (< i l)
      (do-proc (nth self i))
      (set! i (+ 1 i)))))
A session example:
;; (set! r (new (class-rope) 10))
;; (add r 7)
;; (add r 8)
;; (add r 9)
;; (for-elements r write)