Use define/generic:

#lang racket/base

(require racket/generic)

(define-generics foo
  (a foo) (b foo) (c foo)
  #:fallbacks
  [(define/generic gen-a a)
   (define/generic gen-b b)

   (define (a foo)
     (displayln "a-fallback")
     (gen-b foo))
   (define (b foo)
     (displayln "b-fallback")
     (gen-a foo))])

(struct foo-struct ()
  #:methods gen:foo
  [(define (a foo) 1)])

(b (foo-struct))


On Mon, Jul 6, 2015 at 9:50 PM, Alexander D. Knauth
<alexan...@knauth.org> wrote:
> What is the proper way to do this?
>
> This goes into an infinite loop:
>
> #lang racket/base
>
> (require racket/generic)
>
> (define-generics foo
>   (a foo) (b foo) (c foo)
>   #:fallbacks
>   [(define (a foo)
>      (displayln "a-fallback")
>      (b foo))
>    (define (b foo)
>      (displayln "b-fallback")
>      (a foo))])
>
> (struct foo-struct ()
>   #:methods gen:foo
>   [(define (a foo) 1)])
>
> (b (foo-struct))
>
>
> --
> 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.
> For more options, visit https://groups.google.com/d/optout.

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to