# Apparent contradiction in the docs (with resolution?)

**URL:** <https://racket.discourse.group/t/apparent-contradiction-in-the-docs-with-resolution/1003>\
**Category:** General\
**Created:** [May 17, 2022, 7:10pm UTC](https://racket.discourse.group/t/apparent-contradiction-in-the-docs-with-resolution/1003 "2022-05-17T19:10:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dstorrs](https://avatars.discourse-cdn.com/v4/letter/d/898d66/32.png) [@dstorrs](https://racket.discourse.group/u/dstorrs)\
**Post date:** [May 17, 2022, 7:10pm UTC](https://racket.discourse.group/t/apparent-contradiction-in-the-docs-with-resolution/1003/1 "2022-05-17T19:10:35Z")

</div>

[14.5&nbsp;Impersonators and Chaperones](https://docs.racket-lang.org/reference/chaperones.html) says:

> An impersonator cannot be applied to an immutable value or refine the access to an immutable field in an instance of a [structure type](https://docs.racket-lang.org/reference/structures.html#%28tech._structure._type%29), since arbitrary redirection of an operation amounts to mutation of the impersonated value.

On the other hand:

```scheme
> (struct person (name age) #:transparent)
> (define bob (person 'bob 17))                                                   
> (define get (impersonate-procedure person-name (λ (v) (values (λ (v) 'tom) v))))
> (get bob)
'tom

```

After a bit of digging around I realized that, as shown above, it's fine to create a random function that impersonates a struct accessor and save it off somewhere, and that (AFAIK) the restriction only applies to impersonators that are attached to the struct directly by way of `impersonate-struct`:

```scheme
> (impersonate-struct person person-name (λ (self current-val) (displayln "redirected!") current-val))
; impersonate-struct: cannot replace operation for an immutable field                                         
; operation kind: property accessor                                                                         
; operation procedure: #<procedure:person-name>                                                             

```

Do I have this right?

---

<div class="post-metadata">

**Author:** ![samth](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/samth/32/3_2.png) [@samth](https://racket.discourse.group/u/samth)\
**Post date:** [May 17, 2022, 9:08pm UTC](https://racket.discourse.group/t/apparent-contradiction-in-the-docs-with-resolution/1003/2 "2022-05-17T21:08:48Z")

</div>

I think this is a place where the documentation could be clearer. The restriction only applies to immutable _data structures_, like the `person` there or an immutable box, and it applies when wrapping that value in an impersonator, not wrapping an accessor function.

---

<div class="post-metadata">

**Author:** ![dstorrs](https://avatars.discourse-cdn.com/v4/letter/d/898d66/32.png) [@dstorrs](https://racket.discourse.group/u/dstorrs)\
**Post date:** [May 18, 2022, 6:38pm UTC](https://racket.discourse.group/t/apparent-contradiction-in-the-docs-with-resolution/1003/3 "2022-05-18T18:38:47Z")

</div>

So I had it right. Cool, thanks.

---

<div class="post-metadata">

**Author:** ![spdegabrielle](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/spdegabrielle/32/95_2.png) [@spdegabrielle](https://racket.discourse.group/u/spdegabrielle)\
**Post date:** [May 20, 2022, 8:43pm UTC](https://racket.discourse.group/t/apparent-contradiction-in-the-docs-with-resolution/1003/4 "2022-05-20T20:43:02Z")

</div>

If you can think of better text that section can be found in the Racket repository here: [https://github.com/racket/racket/blob/fc41972c9d05510b45f8d3d59407291bbfe10095/pkgs/racket-doc/scribblings/reference/chaperones.scrbl#L32](https://github.com/racket/racket/blob/fc41972c9d05510b45f8d3d59407291bbfe10095/pkgs/racket-doc/scribblings/reference/chaperones.scrbl#L32)

I’d be happy to do a PR on your behalf if that would be helpful.

Bw

Stephen
