[plt-scheme] boxes?

From: Eli Barzilay (eli at barzilay.org)
Date: Wed Jan 24 14:56:09 EST 2007

On Jan 24, hendrik at topoi.pooq.com wrote:
> On Wed, Jan 24, 2007 at 02:33:51PM -0500, Eli Barzilay wrote:
> > On Jan 24, Joe Marshall wrote:
> > > If I could work my will I would remove set! from the language
> > > altogether.
> > 
> > Should be doable now: just make
> > 
> >   (set! id expr)
> > 
> > expand to
> > 
> >   (set-box! id expr)
> That seems to be the opposite of what is wanted.  I think he wants to 
> make set! illegal.  Or change its name to something less analogous -- 
> line setq or maybe even setq!

I can't put words in Joe's mouth, but I think that the core of the
problem is that people are not aware of where the box is created.  For
example, this code:

  (define (foo x)
    (set! x (+ x 1)))
  (define y 0)
  (foo y)

is currently confusing, but with what I described this won't work
because x is not a box -- you'll have to write

  (define (foo x)
    (let ([x (box x)])
      (set! x (+ x 1))))
  (define y 0)
  (foo y)

(which is close to what the language is doing anyway) and it's much
easier to see why it doesn't work.  Then you'll write this:

  (define (foo x)
    (set! x (+ x 1)))
  (define y (box 0))
  (foo y)
  (unbox y)

which is what was originally intended.

On Jan 24, Bill Wood wrote:
> On Wed, 2007-01-24 at 09:17 -0500, hendrik at topoi.pooq.com wrote:
>    . . .
> > Maybe that's why in List 1.5 (anyone remember that one?) they were 
> > called setq and rplaca.
> Actually, Lisp 1.5 had both SET and SETQ; SETQ quotes its first arg.

`SET' is a much more dangerous animal...:

  (let ((x 'y)
        (y 1))
    (set x 10)

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

Posted on the users mailing list.