[plt-scheme] Immutable boxes: why?

From: Sam TH (samth at ccs.neu.edu)
Date: Thu Jun 11 13:53:34 EDT 2009

On Thu, Jun 11, 2009 at 1:20 PM, Matthew Flatt<mflatt at cs.utah.edu> wrote:
> 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.

Literal boxes are used in `match', both in the old-style patterns and
in quasi-patterns.

I'm not suggesting that those uses are worth keeping them, though.

-- 
sam th
samth at ccs.neu.edu


Posted on the users mailing list.