Opened 13 years ago

Closed 13 years ago

#846 closed defect (fixed)

coops: define-method does not redefine

Reported by: megane Owned by: felix winkelmann
Priority: major Milestone:
Component: extensions Version: 4.7.x
Keywords: Cc:
Estimated difficulty:

Description

Below are two cases, first works as expected, second doesn't.

Case 1
(require-extension coops)

(define-class <a> ())

(define b (make <a>))

(define-method (foo (c <a>))

(print "foo v1 on " c))

(define-method (foo (c <a>))

(print "foo v2 on " c))

(foo b)

;; Output:
;; foo v2 on #<coops instance of `<a>'>

Case 2
(require-extension coops)

(define-class <a> ())

(define a (make <a>))

(define-method (foo (a <a>))

(print "foo v1 on " a))

(foo a)

(define-method (foo (a <a>))

(print "foo v2 on " a))

(foo a)

;; Output:
;; foo v1 on #<coops instance of `<a>'>
;; foo v1 on #<coops instance of `<a>'> <-- nothing changed

Change History (5)

comment:1 Changed 13 years ago by megane

You can get the desired effect when using modules. In this case some trickery is needed to not redefine the classes.

(require-extension coops)

(module cls

*
(import chicken scheme)
(use coops)


(define-class <a> ()))

(import cls)
(define a (make <a>))

;; foo v1
(module modu

*
(import chicken scheme)
(use coops)

(import cls)


(define-method (foo (a <a>))

(print "foo v1 on " a)))

(import modu)

(foo a)

;; foo v2
(module modu

*
(import chicken scheme)
(use coops)

(import cls)


(define-method (foo (a <a>))

(print "foo v2 on " a)))

(foo a)

;; Output:
;; foo v1 on #<coops instance of `<a>'>
;; foo v2 on #<coops instance of `<a>'>

comment:2 Changed 13 years ago by megane

Here's a small variation of last comment that doesn't work:

(require-extension coops)

(module cls

*
(import chicken scheme)
(use coops)


(define-class <a> ())

(define-method (foo (a <a>))

(print "foo v1 on " a)))

(import cls)
(define a (make <a>))

(foo a)

;; foo v2
(module modu

*
(import chicken scheme)
(use coops)

(import cls)


(define-method (foo (a <a>))

(print "foo v2 on " a)))

(import modu)
(foo a)

;; Output:
;; foo v1 on #<coops instance of `<a>'>
;; foo v1 on #<coops instance of `<a>'>

comment:3 Changed 13 years ago by felix winkelmann

Owner: set to felix winkelmann
Status: newassigned

This is caused by overeager caching of the method (building coops with -feature no-cache appears to make the exmaple work). I'll try to find a solution to this.

comment:4 Changed 13 years ago by felix winkelmann

Milestone: 4.8.0

comment:5 Changed 13 years ago by felix winkelmann

Resolution: fixed
Status: assignedclosed

I have added an additional cache check, effctively invalidating method caches when a method is defined or re-defined. See coops 0.8 which seems to run your example ok.

Note: See TracTickets for help on using tickets.