[plt-scheme] swindle generic functions top-level and scope

From: Brad (nottysymbaz at yahoo.ca)
Date: Sat Apr 21 23:06:50 EDT 2007

I did some experiments with swindle. I don't care for some of the
behavior. Is it possible to change it with the MOP?

(defclass <foo> ())
(defmethod (bar (self <foo>))
  (printf "bar~n"))

(define foo-1 (make <foo>)) ; this is the control foo.
(define foo-2 (make <foo>)) ; this is the guinea pig foo.

(bar foo-1) ;; -> bar

(let ()
  ;change a method
  (defmethod (bar (self <foo>))
    (printf "noo bar~n"))
  (bar (make <foo>))  ;; -> noo bar
  (bar foo-1)         ;; -> noo bar
  ;export to top level and see if anything changes.
  (set! foo-2 (make <foo>)))

; did anything change?
(bar foo-1)       ;; -> bar (didn't change)
(bar foo-2)       ;; -> bar (didn't change)
; Maybe this is a Good Thing -- I don't know.
; Can change methods locally.

(defclass <foo> ())
(defmethod (bar (self <foo>))
  (printf "noo bar noo foo~n"))
(define foo-2 (make <foo>))

(bar foo-1)   ;; -> bar (an origial foo -- can't make these anymore)
(bar foo-2)   ;; -> noo bar noo foo (this is a noo foo)
(eq? (class-of foo-1) (class-of foo-2)) ;; -> #f
(printf "~a~n" (generic-methods bar))
  ;; -> (#<method:bar:<foo>> #<method:bar:<foo>>)
; This is a Good Thing -- doesn't change the class
; of an object or it's methods.

(let ()
  (bar foo-1)   ;; -> bar
  (bar foo-2))  ;; -> noo bar noo foo
; everything works here.

(let ()
  (defclass <inner-foo> ())
  (defmethod (bar (self <inner-foo>))
    (printf "bar inner foo ~n"))
  (set! foo-2 (make <inner-foo>))
  (bar foo-2)  ;; -> bar inner foo
  ;(bar foo-1) ;; -> error bar: no applicable primary methods...
               ;;    (where is my bar?)
  (printf "~a~n" (generic-methods bar)))
    ;; (#<method:bar:<inner-foo>>) not visible here?
; This is not a Good Thing.

;(bar foo-2) ;; -> error bar: no applicable primary methods...
; I don't know if this is a Good Thing.

Brad



Posted on the users mailing list.