On 21. 12. 20 18:14, George Neuner wrote:
>
> On 12/20/2020 3:34 PM, Dominik Pantůček wrote:
>> Hello Racketeers,
>>
>> there were some discussions about structs' introspection on the IRC
>> lately and one of the questions that arose was how to get field index
>> for arbitrary struct's arbitrary field.
>>
>> Not that it is possible... But the general discussion made me think
>> about why there are no unsafe variants for structs' accessors and
>> mutators.
>
> Have you looked at 'struct-field-info-list' and 'struct-field-index'?
>
> 'struct-field-index' works if you know the field name(s), and
> 'struct-field-info-list' returns fields defined by the struct type - so
> if your structs types are flat, you can make do with these.
>
> However, 'struct-field-info-list' returns only fields defined by the
> actual type and does not include fields that were inherited.  What I
> don't see is any simple way to get at the struct's inheritance hierarchy
> - it seems that you have to iterate 'struct-type-info' to enumerate the
> supertypes.
>
> So it is "possible" (for some definition).
Yes, this approach would be useful to create the unsafe
accessors/mutators after the structs have been defined. Trouble is, one
would have to traverse the structs hierarchy and filter-out those
accessors/mutators, that are already defined by parent struct.

What I wanted to achieve was providing the unsafe variants
"transparently". Honestly, given enough time, the best solution for me
would be adding #:unsafe keyword to the struct form that would define
the unsafe variants.

My usage requires only struct-wide unsafe accessors. I implemented the
rest as an exercise to see what can be done (and to play with more
complex syntax-rules too).

It may be the case that using extract-struct-info and traversing the
structs' hierarchy during expansion phase might be more elegant solution
 for implementing the whole unsafe-struct syntax. I will definitely look
into it more in the (relatively near) future.

Thank you,
Dominik

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/8f73dfb6-62a6-24e4-9eb0-acc5151abadc%40trustica.cz.

Reply via email to