[plt-scheme] Boxing in MzScheme

From: Dor Kleiman (dor at ntr.co.il)
Date: Wed Oct 29 05:15:42 EST 2003

Basically, a box is the Scheme pointer.
Its main usage, I feel, is sending it to functions which change it.
When you use a pair or a struct and set! its parts within the function, it sets it in the caller function as well;
Boxes are used to do exactly that.
(define (add x dx) ; (box integer) integer ->
  (set-box! x (+ (unbox x) dx)))
(define (sum xl) ; (list integer ...) -> integer
  (define x (box 0))
  (define (iter xl)
    (if (not (equal? xl empty))
          (add x (car xl))
          (iter (cdr xl)))))
  (iter xl)
  (unbox x))

	-----Original Message----- 
	From: Khorev Sergey [mailto:Khorev at SoftLab.RU] 
	Sent: ד 29/10/2003 11:47 
	To: 'plt-scheme at list.cs.brown.edu' 
	Subject: [plt-scheme] Boxing in MzScheme

	  For list-related administrative tasks:
	From manual: "MzScheme provides boxes, which are records that have a single
	I wonder, why one-field record is such important so it has its own
	construction? :))
	Or maybe boxing has some special usage?
	I'm knowing about boxing in .NET, where it is used to wrap "simple" data
	types like integers into Object.
	Maybe something similar?
	Sergey Khorev
	As between the skulking and furtive poacher, who hunts for the sake of meat,
	and the honest gentleman shooter, who kills for the pleasure of sport, I
	the former a higher type of humanity.
	 -- Edward Abbey

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20031029/a240d004/attachment.html>

Posted on the users mailing list.