[plt-scheme] foreign library and mutually recursive cstructs

From: John Clements (clements at brinckerhoff.org)
Date: Tue Dec 8 20:40:47 EST 2009

On Dec 8, 2009, at 5:33 PM, John Clements wrote:

> I can't figure out a way to define mutually recursive cstructs.  E.G.:
> #lang scheme
> (require scheme/foreign)
> (define-cstruct _foo
>  ([my-bar _bar-pointer]))
> (define-cstruct _bar
>  ([my-foo _foo-pointer]))
> This signals the error:
> reference to an identifier before its definition: _bar-pointer
> I tried to get around it by finding a way to cast a _bar-pointer to a _foo-pointer, but the "cast" function actually copies memory.

Ah... no, I think I was mistaken about "cast". It doesn't copy the referenced struct, but simply creates a new reference to it... if I'm reading the docs correctly. Using this, then, would require declaring an opaque structure of the correct size and then casting it when required. Mutual recursion would certainly be simpler...


> I could certainly do it by writing my own C library:
> void *anyCast(void * a) {return a};
> (ffi-lib "toBar" myLib (fun _pointer -> _bar-pointer))
> and by changing the definition of _foo so that it contains a _pointer rather than a _bar-pointer, but that seems... needlessly painful.  Is there an obvious way to do this?
> John
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2484 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20091208/9e11c1d8/attachment.p7s>

Posted on the users mailing list.