This is the mail archive of the guile@cygnus.com mailing list for the guile project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
"Peter C. Norton" <spacey@inch.com> writes: > Now that goops is in CVS, I'm wondering if there are any scripts that are > being used as tests to define and debug the behavior of the system? > > I tried to use the example complex number class that's in appendix c of > the stk manual, but the goops'd guile didn't like it. Specificly it > complains about the slots being undefined, failing on the first slot > definition. The problem in this case is that goops appears to want the slots as individual lists after the super definition... and just to solve the next bit that'll bite you after you change that, you need to use guile's #: style keywords; (also, initform is changed to init for some reason). This one should work (though it unearthed a bug in my numbers stuff ;) (define-class <complex> (<number>) (r #:init 0 #:accessor real-part #:init-keyword #:r) (i #:init 0 #:accessor imag-part #:init-keyword #:i) ;; virtual slots access do the conversion (m #:accessor magnitude #:init-keyword #:magn #:allocation #:virtual #:slot-ref (lambda (o) (let ((r (slot-ref o 'r)) (i (slot-ref o 'i))) (sqrt (+ (* r r) (* i i))))) #:slot-set! (lambda (o m) (let ((a (slot-ref o 'a))) (slot-set! o 'r (* m (cos a))) (slot-set! o 'i (* m (sin a)))))) (a #:accessor angle #:init-keyword #:angle #:allocation #:virtual #:slot-ref (lambda (o) (atan (slot-ref o 'i) (slot-ref o 'r))) #:slot-set! (lambda (o a) (let ((m (slot-ref o 'm))) (slot-set! o 'r (* m (cos a))) (slot-set! o 'i (* m (sin a))))))) -- Greg