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 one-place buffers (also called boxes) and mutable pairs.


Boxes


(box? obj)     [procedure]

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

(box obj)     [procedure]

Returns a new box object that contains obj.

(unbox box)     [procedure]

Returns the current content of box. This procedure fails if box is not referring to a box.

(set-box! box obj)     [procedure]

Sets the content of box to 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.