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.
Boxes
(box? obj) [procedure]
Returns #t
if obj is a box; #f
otherwise.
(box obj …) [procedure]
Returns a new box object that contains the objects obj ….
(unbox box) [procedure]
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 …) [procedure]
Sets the content of box to objects obj …. This procedure fails if box is not referring to a box.
(update-box! box proc) [procedure]
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 (proc (unbox box))))
Mutable pairs
(mpair? obj) [procedure]
Returns #t
if v is a mutable pair (mpair); #f
otherwise.
(mcons car cdr) [procedure]
Returns a new mutable pair whose first element is set to car and whose second element is set to cdr.
(mcar mpair) [procedure]
Returns the first element of the mutable pair mpair.
(mcdr mpair) [procedure]
Returns the second element of the mutable pair mpair.
(set-mcar! mpair obj) [procedure]
Sets the first element of the mutable pair mpair to obj.
(set-mcdr! mpair obj) [procedure]
Sets the second element of the mutable pair mpair to obj.