Summary

coops: define-method does not redefine

Metadata

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

Changes and comments

[2012-05-17 23:47:33 UTC] megane wrote:

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>'>

[2012-05-17 23:53:23 UTC] megane wrote:

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>'>

[2012-05-18 12:45:23 UTC] felix changed status from new to assigned

[2012-05-18 12:45:23 UTC] felix set owner to felix

[2012-05-18 12:45:23 UTC] felix wrote:

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.

[2012-05-18 12:45:29 UTC] felix removed milestone 4.8.0

[2012-05-19 13:43:27 UTC] felix changed status from assigned to closed

[2012-05-19 13:43:27 UTC] felix set resolution to fixed

[2012-05-19 13:43:27 UTC] felix wrote:

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.