[racket] Functional Updates for Structs

From: Danny Gratzer (danny.gratzer at gmail.com)
Date: Tue Aug 27 00:37:23 EDT 2013


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

Danny Gratzer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130826/386f4236/attachment.html>

Posted on the users mailing list.