[plt-scheme] Immutable boxes: why?

From: Eli Barzilay (eli at barzilay.org)
Date: Thu Jun 11 12:05:22 EDT 2009

On Jun 11, Luciano Ramalho wrote:
> My understanding of the box datatype was shaken when I read [1] that
> there is an "immutable box" constructor:
> 
> (box-immutable v)
> 
> [1] http://docs.plt-scheme.org/reference/boxes.html
> 
> Can someone please explain what is the use of an immutable box?

It's useful in literals.  Try this in PLT v3xx, and then in v4.x:

  (define (foo)
    (let ([b #&0])
      (set-box! b (add1 (unbox b)))
      (unbox b)))

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!


Posted on the users mailing list.