[racket-dev] cstruct and properties

From: Tobias Hammer (tobias.hammer at dlr.de)
Date: Thu Nov 8 09:20:33 EST 2012

On Thu, 08 Nov 2012 14:55:21 +0100, Matthew Flatt <mflatt at cs.utah.edu>  
wrote:

[ ... ]
> It's interesting that you can make that work in the current
> implementation, but I worry about guaranteeing that order for the
> future. I'm inclined instead to say that the above declaration should
> have signaled an error due to an too-early use of `_S', just like
>
>   (struct a () #:property prop:procedure struct:a)
>
> The repair to `define-cstruct', then, would be to lift the property and
> property-value expressions out of the nested scope where they currently
> are evaluated.
>
> Is it important for your purposes that the `define-cstruct' declaration
> above works? Or could you use a thunk to delay reference, as in
>
>  (define-cstruct _S ([a (_array _byte 23)])
>     #:property p (lambda () _S))
>
> ?

That was a possibility i also tried, but with the same erroneous result.

(define-cstruct _S ([a (_array _byte 23)])
   #:property p (lambda () _S))

(define s (ptr-ref (malloc _S) _S))
(ctype-sizeof ((p-ref s)))
> 4
(ctype-sizeof _S)
> 23

I assume _S binds to the variable in the scope it is defined in,
which is always the temporary cpointer.


-- 
---------------------------------------------------------
Tobias Hammer
DLR / Institute of Robotics and Mechatronics
Muenchner Str. 20, D-82234 Wessling
Tel.: 08153/28-1487
Mail: tobias.hammer at dlr.de

Posted on the dev mailing list.