# Why is contract-out struct immutable?

**URL:** <https://racket.discourse.group/t/why-is-contract-out-struct-immutable/3755>\
**Category:** Questions & Answers\
**Tags:** question\
**Created:** [May 21, 2025, 3:25pm UTC](https://racket.discourse.group/t/why-is-contract-out-struct-immutable/3755 "2025-05-21T15:25:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mike](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@mike](https://racket.discourse.group/u/mike)\
**Post date:** [May 21, 2025, 3:25pm UTC](https://racket.discourse.group/t/why-is-contract-out-struct-immutable/3755/1 "2025-05-21T15:25:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![shawnw](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/shawnw/32/1031_2.png) [@shawnw](https://racket.discourse.group/u/shawnw)\
**Post date:** [May 21, 2025, 11:25pm UTC](https://racket.discourse.group/t/why-is-contract-out-struct-immutable/3755/2 "2025-05-21T23:25:40Z")

</div>

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:

```scheme
#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.

---

<div class="post-metadata">

**Author:** ![mike](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@mike](https://racket.discourse.group/u/mike)\
**Post date:** [May 22, 2025, 6:18am UTC](https://racket.discourse.group/t/why-is-contract-out-struct-immutable/3755/3 "2025-05-22T06:18:29Z")

</div>

Ah, I didn't know that - many thanks!
