[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.
e.g.
 
(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))
        (begin
          (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' 
	Cc: 
	Subject: [plt-scheme] Boxing in MzScheme
	
	

	  For list-related administrative tasks:
	  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
	
	From manual: "MzScheme provides boxes, which are records that have a single
	field."
	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
	http://iamphet.nm.ru
	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
	find
	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.