Well, as I understand it, a struct (usually? always?), #:transparent or
not, when declared, defines symbols that are meant to be visible in the
current scope, so (struct foo (a b)) defines foo #|constructor|#, foo?
#|instance-predicate|# foo-a and foo-b #|data accessors|# , that I can call
on instances:
(struct foo (a b))
(let ([my-foo (foo 42 37)]
(list (foo? my-foo)
(foo-a my-foo)
(foo-b my-foo))) ~~> '(#t 42 37)
I would like, given only the symbol foo referring to the struct type
itself, to discover (at least) the list of procedures foo?, foo-a, foo-b,
plus anything else the author of foo (the type) wants me to see.
On Fri, Oct 29, 2021 at 1:45 PM John Clements <[email protected]>
wrote:
> In the text below, you refer to the “public” interface. Can I ask what you
> mean by “public” in this context?
>
> John
>
> > On Oct 29, 2021, at 11:16 AM, Brian Beckman <[email protected]>
> wrote:
> >
> > I believe that run time will be the most plausible use case. I may write
> macros that refer to struct-procedure names at macro-writing time, but I
> don't expect to invoke the struct procedures at macro-expansion time. My
> primary issue is "discoverability:" how can I find out the interface of any
> struct?
> >
> > On Thursday, October 28, 2021 at 1:00:15 PM UTC-7 [email protected]
> wrote:
> > Are you intending to use the struct procedure names at compile time
> (such as in a macro) or runtime?
> >
> > On Tuesday, October 26, 2021 at 5:02:46 PM UTC-7 [email protected]
> wrote:
> > I understand why structs are opaque, by default, but I want to discover
> the public interface of some struct type, that is, a list of the procedures
> defined by the struct.
> >
> > Here is an example. Suppose I want to find out all the procedures
> defined on an instance of the syntax struct
> >
> > #'42
> >
> > Dr. Racket shows an expander clicky that shows some formatted
> information inside the instance :
> >
> >
> >
> > Uncapitializing the names in the display reveals the interface:
> >
> > (syntax-position #'42) ~~> 790
> > (syntax-span #'42) ~~> 2
> > (syntax-original? #'42) ~~> #t
> >
> > etc.
> >
> > I want to discover those procedure names in my racket program, not
> manually by visually inspecting graphics in Dr Racket.
> >
> > I found this trick for structs that I define:
> >
> > #lang racket
> > (require (for-syntax racket/struct-info))
> > (require racket/pretty)
> >
> > (struct foo (a b))
> > (begin-for-syntax
> > (displayln
> > (extract-struct-info
> > (syntax-local-value
> > #'foo))))
> >
> > ~~>
> >
> >
> >
> > but it doesn't work for the syntax type
> >
> > (begin-for-syntax
> > (displayln
> > (extract-struct-info
> > (syntax-local-value
> > #'syntax))))
> >
> > ~~>
> >
> >
> >
> > I'd be grateful for advice and an example of how to get the interface of
> "syntax" without Dr Racket and without grovelling docs.
> >
> > --
> > 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 [email protected].
> > To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/8e4ca03e-e276-4c42-a662-4fcf7c994387n%40googlegroups.com
> .
>
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/racket-users/CAK2VK6tMxFH0oEq4iCgk7PW-4yJTB8xNr_b3F6GPwQS1MZVLwQ%40mail.gmail.com.