[plt-scheme] Native code generation and immutable pairs

From: Gregory Woodhouse (gregory.woodhouse at sbcglobal.net)
Date: Sun Feb 12 10:54:56 EST 2006

On Feb 12, 2006, at 5:06 AM, Robby Findler wrote:

> Yes. SML, for example, only has mutable boxes (they call them  
> `ref's) and nothing else in the language is mutable. Maybe looking  
> there will give you some insight.
>
> Robby

It's not that I don't think I understand how to use boxes (which  
isn't to say that I actually understand them), I'm just trying to  
imagine why they might be needed in a language allowing mutation. To  
tell you the truth, I was quite surprised by chapter 3 of SICP  
because I had tacitly assumed creating graphs (rather than trees) out  
of pairs was impossible.

I did look in the help desk, and found list-immutable, which behaves  
just as I expect

 > (define x (list-immutable 1 2))
 > (set-car! x 2)
. set-car!: expects type <mutable-pair> as 1st argument, given: (1  
2); other arguments were: 2

I do find, however, that I can use a box and achieve the effect of  
"modifying" the car

 > (define y (list-immutable (box 1) 2))
 > (set-box! (car y) 2)
 > (unbox (car y))
2

and I suppose I meant to confirm that this behavior would still be  
supported.

My other question (or was it a comment?) was of a different nature: I  
find it interesting that Scheme includes both boxes and mutable  
pairs, and I guess I'm trying to understand why boxes might be needed  
if you have set-car! and set-cdr!


===
Gregory Woodhouse
gregory.woodhouse at sbcglobal.net

"You can't win if you don't finish the race."
--Richard Petty





Posted on the users mailing list.