<HTML><BODY>Recommended way for mutual dependencies is to use units:<br><br><a href="http://docs.racket-lang.org/guide/units.html">http://docs.racket-lang.org/guide/units.html</a><br><br>You may define struct accessors as unit exports/imports and then link them<br><br><br>Mon, 18 Aug 2014 23:44:11 -0400 от Jon Zeppieri <zeppieri@gmail.com>:<br>
<blockquote style="border-left:1px solid #0857A6; margin:10px; padding:0 0 0 10px;">
<div id="">
<div class="js-helper js-readmsg-msg">
<style type="text/css"></style>
<div>
<base target="_self" href="https://e.mail.ru/">
<div id="style_14084204110000000703_BODY">Say I want to do basically the following, except with larger, more<br>
complicated generic interfaces:<br>
<br>
```racket<br>
#lang racket/base<br>
<br>
(require racket/generic)<br>
<br>
(define-generics ->foo-provider<br>
(->foo ->foo-provider))<br>
<br>
(define-generics ->bar-provider<br>
(->bar ->bar-provider))<br>
<br>
(struct foo (x)<br>
#:methods gen:->foo-provider<br>
[(define (->foo f) f)]<br>
<br>
#:methods gen:->bar-provider<br>
[(define (->bar f) (bar (foo-x f)))])<br>
<br>
(struct bar (x)<br>
#:methods gen:->foo-provider<br>
[(define (->foo b) (foo (bar-x b)))]<br>
<br>
#:methods gen:->bar-provider<br>
[(define (->bar b) b)])<br>
```<br>
<br>
That is, I want to have struct types that can use generic methods to<br>
construct instances of one another. Since the actual struct types are<br>
rather more complicated than this example, I'd really like to split up<br>
their implementations into separate modules. If I weren't using<br>
generics, this would be straightforward; I'd put the struct type<br>
definitions themselves in a module, or set of modules, and I'd put the<br>
operations in modules specific to their respective struct types. The<br>
modules containing the operations would be able to require all of the<br>
struct type definitions, so they could freely construct instances of<br>
one another.<br>
<br>
In the present case, however, the method implementations need to be<br>
defined along with the struct type definition. I can't do something<br>
like:<br>
<br>
```<br>
[(define ->foo bar->foo)]<br>
```<br>
... where bar->foo comes from a bar-specific module, because that<br>
would lead to a circular dependency (bar->foo needs the foo<br>
constructor, which is defined in this module, while this module needs<br>
bar->foo).<br>
<br>
I could work around this with mutable bindings (either at the module<br>
level or, better, in method dispatch), but I'm not fond of either<br>
approach. With the right structure inspector maybe (?) it would be<br>
possible to modify whatever dispatch table is actually used, but that<br>
sounds hairy. I guess I'm wondering if some other trick is possible<br>
here.<br>
<br>
-Jon<br>
____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
</div>
<base target="_self" href="https://e.mail.ru/">
</div>
</div>
</div>
</blockquote>
<br>
<br>-- <br>Roman Klochkov<br></BODY></HTML>