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.
Returns #t if v is a box, #f otherwise.
See also immutable-box? and mutable-box?.
Returns a new mutable box that contains v.
Returns a new immutable box that contains v.
Returns the content of box.
For any v, (unbox (box v)) and (unbox (box-immutable v)) returns v.
Sets the content of box to v.
Added in version 6.90.0.15 of package base.
Atomically updates the contents of
boxto
new, provided that
boxcurrently contains a value that is
eq?to
old, and returns
#tin that case. If
boxdoes not contain
old, then the result is
#f.
If no other threads or futures attempt to access box, the operation is equivalent to
except that box-cas! can spuriously fail on some platforms. That is, with low probability, the result can be #f with the value in box left unchanged, even if box contains old.
When Racket is compiled with support for futures, box-cas! is guaranteed to use a hardware compare and set operation. Uses of box-cas! can be performed safely in a future (i.e., allowing the future thunk to continue in parallel). See also Machine Memory Order.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4