[racket] Are there any functional structs in Racket

From: Nikita B. Zuev (nikitazu at gmail.com)
Date: Wed Oct 20 03:16:14 EDT 2010

I'm looking for a way to use Raket's structs in a functional way.

(define-struct person (name age))

(define p (make-person "Nikita" 25))

;; in documentation I found only setters, that mutate struct:

(person-set-age! p 26)

;; to make functional update I have to write

(define p1 (make-person (person-name p)
                        (add1 (person-age p))))

;; I can write my own setters like this:

(define (person-age-set p proc)
  (make-person (person-name p)
               (proc (person-age p))))

(define p2 (person-age-set p add1))

It would be great if functional setters could be generated by some
macro. Does such macro exist? Or maybe I need to provide some keyword
to struct definition?

Nikita B. Zuev

Posted on the users mailing list.