Functionally (ie. immutably) updating a Racket object

Viewed 260

Say I define a class in Racket with about 30 fields.

And I want to treat these as immutable. In other words I never update the object in place, just create a new object with 29 of the fields containing the same values and one with the over-written value.

Are there any convenience functions to do this?

At the moment I'm rather laboriously writing a function like

(define/public (overwrite-n n-val) 
    (new MyClass% [a (get-a)] [b (get-b)] [c (get-c)] ... [n n-val] ... ))

for each field I want to be able to update. There must be a better way to do this.

1 Answers
Related