[plt-scheme] Immutable boxes: why?

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Thu Jun 11 13:20:08 EDT 2009

At Thu, 11 Jun 2009 12:05:22 -0400, Eli Barzilay wrote:
> 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)))

Although this illustrates why literal boxes should not be mutable, it
begs the question of why literal boxes exist at all. Literal boxes are
a just holdover from earlier days, and I know of no good use for them.



Posted on the users mailing list.