Skip to content

Commit 6c3a511

Browse files
committed
mutable read-only example
1 parent eaf7a6d commit 6c3a511

File tree

1 file changed

+6
-1
lines changed
  • typed-racket-doc/typed-racket/scribblings/reference

1 file changed

+6
-1
lines changed

typed-racket-doc/typed-racket/scribblings/reference/types.scrbl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,12 @@ is a subtype of @racket[(Read-Only-Boxof b)] if @racket[a] is a subtype of @rack
361361

362362
@ex[(box-immutable "hello world")
363363
(code:comment "though this does not necessarily imply immutability:")
364-
(if (zero? (random 2)) (box "hello") (box 'hello))]
364+
(define b : (Box Integer) (box 3))
365+
(define b-read-only : (Read-Only-Boxof Integer) b)
366+
(set-box! b-read-only 5)
367+
(unbox b-read-only)
368+
(set-box! b 5)
369+
(unbox b-read-only)]
365370

366371
@defidform[BoxTop]{is the type of a @rtech{box} with an unknown element
367372
type and is the supertype of all box types. Only read-only box operations

0 commit comments

Comments
 (0)