Hi guys,
If I create a generic, say foo, for a particular struct and then later 
reference that method on a different type of struct from within the handler 
method I get an error because the call goes to the original structs method and 
not to the method of the other struct. Is there a way to do this?

Here’s a very artificial example:

#lang racket

(require racket/generic)

(define-generics foo
    [do-foo foo])

(struct A (this other) #:transparent
  #:methods gen:foo
  [(define (do-foo foo)
     (printf "other=~a ~a"
             (A-this foo)
             (do-foo (A-other foo))))])
(struct B (lst) #:transparent
  #:methods gen:foo
  [(define (do-foo foo)
     (printf "lst=~a"
             (B-lst foo)))])

(define b (B '(x y z)))
(define a (A 'a b))

(do-foo b) ;=> lst=(x y z)

(do-foo a) ;=> A-this: contract violation
  expected: A?
  given: (B '(x y z))

Thanks, 
Kevin

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/86CD099C-EC82-4F97-B20A-784933E3C6FC%40gmail.com.

Reply via email to