(use test srfi-1 srfi-13) (use coops coops-introspection coops-extras) (define-class () ((x 's1xy-x) (y 's1xy-y))) (define-class () ((a 's1ab-a) (b 's1ab-b))) (define-class () ((x 's2xz-x) (z 's2xz-z))) (define-class () ((a 's2ac-a) (c 's2ac-c))) (define-class ( ) ((x 's1xys1ab-x) (y 's1xys1ab-y) (a 's1xys1ab-a) (b 's1xys1ab-b) (me '))) (define-class ( ) ((x 's2xzs2ac-x) (z 's2xzs2ac-z) (a 's2xzs2ac-a) (c 's2xzs2ac-c))) (define-class ( ) ()) (define-class ( ) ()) (define-generic (foo abc xyz)) (define-method (foo primary: (abc ) (xyz )) 'primary-) (define-method (foo before: (abc ) (xyz )) 'before-) (define-method (foo after: (abc ) (xyz )) 'after-) (define-method (foo around: (abc ) (xyz )) 'around-) (define-method (foo primary: (abc ) (xyz )) 'primary-) (define-method (foo before: (abc ) (xyz )) 'before-) (define-method (foo after: (abc ) (xyz )) 'after-) (define-method (foo around: (abc ) (xyz )) 'around-) (test-assert (class? )) (test-assert (class? )) (test (list ) (class-precedence-list )) (test '(x z a b) (class-slots )) (test-assert (class? )) (test (list ) (class-direct-supers )) (test '(a c) (class-direct-slots )) (test-assert (class? )) (test (list ) (class-direct-supers )) (test '(me) (class-direct-slots )) (test 'foo (generic-name foo)) (test '(abc xyz) (generic-specialized-arguments foo)) (let ((primaries (generic-methods foo))) (for-each (lambda (x) (test-assert (method? x)) (let ((specials (method-specializers x))) (test-assert (list? specials)) (test-assert (every class? specials)) ) (test-assert (procedure? (method-procedure x))) ) primaries) ) ;instance? x ;instance-of? ;primitive-instance? ;slot@ ;make/copy ;describe-object ;--- #| ;; Named (has a name) "concept" (define-generic (name obj)) (define-class () ( (namsym #:reader name) ) ) ;; Moves foreward thru a set of values "concept" (define-generic (step-function obj)) (define-class () ( (nxtval #:reader step-function) ) ) (define-generic (next-value obj)) (define-method (next-value (obj )) ((step-function obj))) ;; Parameterized extension "concept" (define-generic (parameters obj)) (define-generic (basis obj)) (define-class () ( (parms #:reader parameters) (src #:reader basis) ) ) ;; Parameterized generative set of random values "concept" (define-class ( ) ( temp ) ) ;; Create an instance of where the arguments are ;; the same as the documented procedural distribution API. ;; ;; SRFI 27 API: ({some distribution constructor} arg...) ;; OO API: (make-random-distribution {some distribution constructor} arg...) (define-syntax make-random-distribution (syntax-rules () ((_ ?ctor ?arg0 ...) (make 'temp (?ctor ?arg0 ...)) ) ) ) (define-method (initialize-instance (obj )) ; The 'ctor' should be a globally defined procedure compiled ; with procedure-information. So if following nomenclature then the last ; procedure name element will be the kind of distribution. (let* ((temp (slot-value obj 'temp)) (ctor (car temp)) (procinfo (procedure-information ctor)) (name (and procinfo (pair? procinfo) (symbol->string (car procinfo)))) (name (and name (and-let* ((kndpos (string-index-right name #\-))) (substring/shared name (fx+ kndpos 1)) ) ) ) (dstr-vals (receive (apply ctor (cdr temp)))) (parms (and (fx<= 2 (length dstr-vals)) (receive ((second dstr-vals))))) ) (set! (slot-value obj 'temp) #f) ;"free" the "any" slot (set! (slot-value obj 'namsym) (string->symbol name)) (set! (slot-value obj 'nxtval) (first dstr-vals)) (set! (slot-value obj 'parms) (and parms (drop-right parms 1))) |#