[plt-scheme] Structure constructor
Along the same lines, is there a way to get the field names for a structure?
I've already added structure matching to the inference collection using
vectors. This is strictly matching by position. I would like to add
matching by field name. I already have the syntax elements for fields
(keys) because I have matching against association lists as part of the list
matching code.
Doug
> -----Original Message-----
> From: plt-scheme-bounces at list.cs.brown.edu [mailto:plt-scheme-
> bounces at list.cs.brown.edu] On Behalf Of Jens Axel Søgaard
> Sent: Monday, July 17, 2006 12:27 PM
> Cc: plt-scheme at list.cs.brown.edu
> Subject: Re: [plt-scheme] Structure constructor
>
> Robby Findler wrote:
>
> >At Mon, 17 Jul 2006 14:16:00 -0400, Sam TH wrote:
> >
> >
> >>On Mon, 2006-07-17 at 20:03 +0200, Jens Axel Søgaard wrote:
> >>
> >>
> >>>Hi all,
> >>>
> >>>What is the simplest way to go from a structure to its constructor?
> >>>The following seems to work, but I have a hunch there is a simpler
> >>>solution.
> >>>
> >>>
> >>I think you want `struct-type-make-constructor'. Then your function can
> >>be defined as:
> >>
> >>(define (struct-constructor s)
> >> (define-values (sty _) (struct-info s))
> >> (struct-type-make-constructor sty))
> >>
> >>
> >
> >You can also get that information at elaboration time, if you have the
> >"s" in (define-struct s (a b)) around. define-struct's docs should
> >explain how to extract it, I believe.
> >
> >
> Yes, in this case I need it at evaluation time though. I am writing a
> general clone
> function for syntax trees represented by structures.
>
> --
> Jens Axel Søgaard
>
>
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme