(lispkit box)
LispKit is a R7RS-compliant implementation with one exception: pairs are immutable. This library provides implementations of basic mutable data structures with reference semantics: mutable multi-place buffers, also called boxes, and mutable pairs. The difference between a two-place box and a mutable pair is that a mutable pair allows mutations of the two elements independent of each other.
(box? obj)

Returns
#t
if obj is a box; #f
otherwise.(box obj ...)

Returns a new box object that contains the objects obj ....
(unbox box)

Returns the current contents of box. If multiple values have been stored in the box,
unbox
will return multiple values. This procedure fails if box is not referring to a box.(set-box! box obj ...)

Sets the content of box to objects obj .... This procedure fails if box is not referring to a box.
(update-box! box proc)

Invokes proc with the content of box and stores the result of this function invocation in box.
update-box!
is implemented like this:(define (update-box! box proc)
(set-box! box (apply-with-values proc (unbox box))))
(mpair? obj)

Returns
#t
if v is a mutable pair (mpair); #f
otherwise.(mcons car cdr)

Returns a new mutable pair whose first element is set to car and whose second element is set to cdr.
(mcar mpair)

Returns the first element of the mutable pair mpair.
(mcdr mpair)

Returns the second element of the mutable pair mpair.
(set-mcar! mpair obj)

Sets the first element of the mutable pair mpair to obj.
(set-mcdr! mpair obj)

Sets the second element of the mutable pair mpair to obj.
Last modified 11mo ago