4.12 Boxes
Boxes in The Racket Guide introduces boxes.
A box is like a single-element vector, normally used as minimal mutable storage.
A box can be mutable or immutable. When an immutable box is provided to a procedure like set-box!, the exn:fail:contract exception is raised. Box constants generated by the default reader (see Reading Strings) are immutable. Use immutable? to check whether a box is immutable.
A literal or printed box starts with #&. See Reading Boxes for information on reading boxes and Printing Boxes for information on printing boxes.
procedure
(box-immutable v) → (and/c box? immutable?)
v : any/c
For any v, (unbox (box v)) returns v.
procedure
box : (and box? (not/c impersonator?))
procedure
box : (and/c box? (not/c immutable?) (not/c impersonator?)) v : any/c
Added in version 6.90.0.15 of package base.
procedure
box : (and/c box? (not/c immutable?) (not/c impersonator?)) old : any/c new : any/c
If no other threads or futures attempt to access box, the operation is equivalent to
When Racket is compiled with support for futures, box-cas! uses a hardware compare and set operation. Uses of box-cas! be performed safely in a future (i.e., allowing the future thunk to continue in parallel).