[racket] Functional Updates for Structs

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Tue Aug 27 09:59:27 EDT 2013

Danny,

this is indeed an Achilles' heel in our world. Can you give us some more context? If you don't have access to the name of the struct type, how would you access the fields of a struct? How do you know anything about it? 

For better or worse, Racket has chosen a slightly more static approach to structs than other scripting languages, from which you get a bit more safety and a bit more hassle. 

-- Matthias







On Aug 27, 2013, at 12:37 AM, Danny Gratzer <danny.gratzer at gmail.com> wrote:

> Hello,
> 
> I'm writing some code to manipulate a few structs and in doing so have run into a rub. There doesn't seem to be a convenient way to do functional updates for structs.
> 
> Normally I'd use struct-copy, but I have neither the field nor the type name at compile time, currently I have a macro that looks like this
> 
>     (wire some-struct-accessor ; source
>             some-proc                ; pipe
>             (lambda (s v) (struct-copy type-name s [field-name v]))) ; sink
> 
> which just looks clunky when compared to the functional accessor. My research turned up a thread[1] from 2010 that proposed 
> 
>     (type-name/field struct val)
> 
> as an updater counterpart to 
> 
>     (type-name-field struct)
> 
> but that doesn't seem to have gone anywhere.
> 
> I figured I'd ask to see if I'm about to reinvent the wheel here before I just write some code to generate my update functions.
> 
> [1] http://lists.racket-lang.org/users/archive/2010-October/042390.html
> 
> Cheers,
> Danny Gratzer
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users



Posted on the users mailing list.