[racket] Generics and modules

From: J. Ian Johnson (ianj at ccs.neu.edu)
Date: Tue Aug 27 11:43:45 EDT 2013

No, your function is just ill-founded. Do you mean to destruct x to find an inner bar to call gen-foo-far-baz on it?
-Ian
----- Original Message -----
From: "Konrad Hinsen" <konrad.hinsen at fastmail.net>
To: users at racket-lang.org
Sent: Tuesday, August 27, 2013 11:37:21 AM GMT -05:00 US/Canada Eastern
Subject: Re: [racket] Generics and modules

Asumu Takikawa writes:

 > This is what the `define/generic` form is for. You can then re-write
 > your struct definition as

Great, thanks! I had seen define/generic but its documentation made me
believe that its use is more restricted. But it works fine in my
demonstration code.

Unfortunately, I did not manage to fix the real code that motivated my
question using the same trick. The difference is that in the real code,
the method name shadows not a local function, but a field accessor in
the very structure that I am defining the methods for.

Here's an updated version of my demo code:

-- foo.rkt ------------------------------------------------
#lang racket

(provide (all-defined-out))

(require racket/generic)

(define-generics bar
  [foo-bar-baz bar])
-----------------------------------------------------------

-- foo-bar.rkt --------------------------------------------
#lang racket

(provide (all-defined-out))

(require (prefix-in foo: "foo.rkt")
         (only-in racket/generic define/generic))

(struct foo-bar (baz)
        #:methods foo:gen:bar
        [(define/generic gen-foo-bar-baz foo-bar-baz)
         (define (foo-bar-baz x)
           (gen-foo-bar-baz x))])
-----------------------------------------------------------

Then, in a REPL:

    (require (prefix-in foo: "foo.rkt")
             "foo-bar.rkt")
    (foo:foo-bar-baz (foo-bar 42))

This hangs in the method foo-bar-baz, so it looks like my
freshly defined gen-foo-bar-baz still refers to the method
being defined.

Is there a workaround for that case as well?

Thanks,
  Konrad.
____________________
  Racket Users list:
  http://lists.racket-lang.org/users

Posted on the users mailing list.