summaryrefslogtreecommitdiffstats
path: root/object.scm
diff options
context:
space:
mode:
authorJames LewisMoss <dres@debian.org>1999-12-06 19:32:57 -0500
committerBryan Newbold <bnewbold@robocracy.org>2017-02-20 00:05:28 -0800
commitc394920caedf3dac1981bb6b10eeb47fd6e4bb21 (patch)
treef21194653a3554f747dde3df908df993c48db5a0 /object.scm
parent926b1b647ac830660933a5e63eb52d4a2552e264 (diff)
parentbd9733926076885e3417b74de76e4c9c7bc56254 (diff)
downloadslib-c394920caedf3dac1981bb6b10eeb47fd6e4bb21.tar.gz
slib-c394920caedf3dac1981bb6b10eeb47fd6e4bb21.zip
Import Debian changes 2c7-1debian/2c7-1
slib (2c7-1) unstable; urgency=low * New upstream. * Add slibconfig back in. slib (2c6-2) unstable; urgency=low * Remove the slib$(VERSION).info file. Cut the diff back down to size. slib (2c6-1) unstable; urgency=low * New upstream. * Move docs to /usr/share. Up standards version. add /usr/doc symlink. Move info files. Remove undocumented link. slib (2c5-6) unstable; urgency=low * Lowercase two vars in yasyn.scm (Fixes bug #37222) slib (2c5-5) unstable; urgency=low * Fix it so string-index isn't defined (now there is a strsrch:string-index) (Fixes #38812) slib (2c5-4) unstable; urgency=low * Don't run slibconfig in postinst. (Fixes bug #38253, #37733, #37715, #37746, #37809, #37917, #38123, #38462) slib (2c5-3) unstable; urgency=low * Run slibconfig in postinst. It was commented out there, but I don't see any old bug reports on why it was commented out, so let's try again. :) (Fixes bug #37221) slib (2c5-2) unstable; urgency=low * Link mklibcat.scm to mklibcat. Fixes a problem with using slib with guile. slib (2c5-1) unstable; urgency=low * New upstream. slib (2c3-4) unstable; urgency=low * New maintainer.
Diffstat (limited to 'object.scm')
-rw-r--r--object.scm97
1 files changed, 97 insertions, 0 deletions
diff --git a/object.scm b/object.scm
new file mode 100644
index 0000000..c272ef9
--- /dev/null
+++ b/object.scm
@@ -0,0 +1,97 @@
+;;; "object.scm" Macroless Object System
+;;;From: whumeniu@datap.ca (Wade Humeniuk)
+
+;;;Date: February 15, 1994
+
+;; Object Construction:
+;; 0 1 2 3 4
+;; #(object-tag get-method make-method! unmake-method! get-all-methods)
+
+(define object:tag "object")
+
+;;; This might be better done using COMLIST:DELETE-IF.
+(define (object:removeq obj alist)
+ (if (null? alist)
+ alist
+ (if (eq? (caar alist) obj)
+ (cdr alist)
+ (cons (car alist) (object:removeq obj (cdr alist))))))
+
+(define (get-all-methods obj)
+ (if (object? obj)
+ ((vector-ref obj 4))
+ (slib:error "Cannot get methods on non-object: " obj)))
+
+(define (object? obj)
+ (and (vector? obj)
+ (eq? object:tag (vector-ref obj 0))))
+
+(define (make-method! obj generic-method method)
+ (if (object? obj)
+ (if (procedure? method)
+ (begin
+ ((vector-ref obj 2) generic-method method)
+ method)
+ (slib:error "Method must be a procedure: " method))
+ (slib:error "Cannot make method on non-object: " obj)))
+
+(define (get-method obj generic-method)
+ (if (object? obj)
+ ((vector-ref obj 1) generic-method)
+ (slib:error "Cannot get method on non-object: " obj)))
+
+(define (unmake-method! obj generic-method)
+ (if (object? obj)
+ ((vector-ref obj 3) generic-method)
+ (slib:error "Cannot unmake method on non-object: " obj)))
+
+(define (make-predicate! obj generic-predicate)
+ (if (object? obj)
+ ((vector-ref obj 2) generic-predicate (lambda (self) #t))
+ (slib:error "Cannot make predicate on non-object: " obj)))
+
+(define (make-generic-method . exception-procedure)
+ (define generic-method
+ (lambda (obj . operands)
+ (if (object? obj)
+ (let ((object-method ((vector-ref obj 1) generic-method)))
+ (if object-method
+ (apply object-method (cons obj operands))
+ (slib:error "Method not supported: " obj)))
+ (apply exception-procedure (cons obj operands)))))
+
+ (if (not (null? exception-procedure))
+ (if (procedure? (car exception-procedure))
+ (set! exception-procedure (car exception-procedure))
+ (slib:error "Exception Handler Not Procedure:"))
+ (set! exception-procedure
+ (lambda (obj . params)
+ (slib:error "Operation not supported: " obj))))
+ generic-method)
+
+(define (make-generic-predicate)
+ (define generic-predicate
+ (lambda (obj)
+ (if (object? obj)
+ (if ((vector-ref obj 1) generic-predicate)
+ #t
+ #f)
+ #f)))
+ generic-predicate)
+
+(define (make-object . ancestors)
+ (define method-list
+ (apply append (map (lambda (obj) (get-all-methods obj)) ancestors)))
+ (define (make-method! generic-method method)
+ (set! method-list (cons (cons generic-method method) method-list))
+ method)
+ (define (unmake-method! generic-method)
+ (set! method-list (object:removeq generic-method method-list))
+ #t)
+ (define (all-methods) method-list)
+ (define (get-method generic-method)
+ (let ((method-def (assq generic-method method-list)))
+ (if method-def (cdr method-def) #f)))
+ (vector object:tag get-method make-method! unmake-method! all-methods))
+
+