mike
May 21, 2025, 3:25pm
1
It seems struct
in contract-out
does not support the #:mutable
option. Why is that? This is especially strange as struct/contract
does support it.
This is regrettable, as changing one into the other is super-tedious. I generally wish there was a bit of advice that would tell me which one to use.
shawnw
May 21, 2025, 11:25pm
2
It's not? The contract-out
struct
form automatically detects mutable fields and provides the setter functions with contracts based on the ones for those fields:
#lang racket
(module demo racket
(provide (contract-out (struct foo ([a string?]))))
(struct foo ([a #:mutable]) #:transparent))
(require 'demo)
(define x (foo "bar"))
(set-foo-a! x 42) ; contract violation
No need to explicitly tell it a field is mutable.
mike
May 22, 2025, 6:18am
3
Ah, I didn't know that - many thanks!