guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[1.6.4 GOOPS] no (next-method) in accessor?


From: Steve Tell
Subject: [1.6.4 GOOPS] no (next-method) in accessor?
Date: Sun, 25 Jul 2004 17:17:23 -0400 (EDT)

I just started working with (oop goops) in guile 1.6.4, and have run into 
a problem.   In a subclasse's accessor's #:slot-set! routine, I wanted to 
do some additional setup and checking and then call the base class's 
accessor to do most of the work.  
But even though the documentation suggests that accessors are generic 
functions, (next-method) doesn't seem to work.

Is there somthing I'm doing wrong in the example below?  Or are accessors 
not really full-featured generic functions in this sense?

Steve

(P.S. Since my previous OO experience has been with Eiffel, 1995-vintage
C++ and perl, parts of goops are a bit alien to me.  But so far I like
it.)





(use-modules  (ice-9 format) (oop goops) (oop goops describe))

(define (ctrlpt-print-statechange o old new)
  (format #t "--ctrlpt ~s ~s=>~s\n" (name o) old new))

(define-class <ctrlpt> ()
  (name #:init-value "" #:init-keyword #:name #:getter name)
  (curstate #:init-value #f)
  (hook #:init-thunk (lambda () (make-hook 3)))
  (state #:accessor state
         #:allocation #:virtual 
         #:slot-ref (lambda (o) (slot-ref o 'curstate))
         #:slot-set! (lambda (o ns)
                       (let ((oldval (slot-ref o 'curstate)))
                         (slot-set! o 'curstate ns)
                         (run-hook (slot-ref o 'hook) o oldval ns)))
         )
  (verbose #:accessor verbose
           #:allocation #:virtual
           #:init-value #f
           #:slot-ref (lambda (o) 
                        (not(not(member ctrlpt-print-statechange 
                                        (hook->list (slot-ref o 'hook))))))
           #:slot-set! (lambda (o v)
                         (if v
                             (add-hook! (slot-ref o 'hook)
                                        ctrlpt-print-statechange)
                             (remove-hook! (slot-ref o 'hook) 
                                           ctrlpt-print-statechange)))
           )
)

(define-class <boolean-ctrlpt> (<ctrlpt>)
  (state 
   #:allocation #:virtual
   #:accessor state
   #:slot-ref (lambda (o) (next-method))
   #:slot-set! (lambda (o ns)
                 (if (not (boolean? ns))
                     (error "<boolean-ctrlpt> new state must be boolean"))
                 (next-method) ; fails ERROR: No next method when calling 
#<<generic> setter:state (2)>
)))

(define-method (increment! (o <boolean-ctrlpt>))
  (set! (state o) (not (state o))))

; blowing off accessors and defining our own generic methods works
(define-method (ctrlpt-set-state! (o <ctrlpt>) ns)
  (let ((oldval (slot-ref o 'curstate)))
    (slot-set! o 'curstate ns)
    (run-hook (slot-ref o 'hook) o oldval ns)))

(define-method (ctrlpt-set-state! (o <boolean-ctrlpt>) ns)
  (if (not (boolean? ns))
      (error "<boolean-ctrlpt> new state must be boolean"))
  (next-method)
)


(define cp (make <ctrlpt> #:name "testpt"))
(slot-set! cp 'state #t)
(set! (state cp) #t)
(ctrlpt-set-state! cp #f)

(define bp (make <boolean-ctrlpt> #:name "btst"))
(ctrlpt-set-state! bp #t) ; works
(set! (state bp) #t)  ; fails  here
(increment! bp) ; fails here too








reply via email to

[Prev in Thread] Current Thread [Next in Thread]