<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META NAME="Generator" CONTENT="MS Exchange Server version 6.0.6249.1">
<TITLE>[plt-scheme] Boxing in MzScheme</TITLE>
</HEAD>
<BODY dir=ltr>
<DIV>Basically, a box is the Scheme pointer.</DIV>
<DIV>Its main usage, I feel, is sending it to functions which change it.</DIV>
<DIV>When you use a pair or a struct and set! its parts within the function, it
sets it in the caller function as well;</DIV>
<DIV>Boxes are used to do exactly that.</DIV>
<DIV>e.g.</DIV>
<DIV> </DIV>
<DIV>(define (add x dx) ; (box integer) integer -></DIV>
<DIV> (set-box! x (+ (unbox x) dx)))</DIV>
<DIV> </DIV>
<DIV>(define (sum xl) ; (list integer ...) -> integer</DIV>
<DIV> (define x (box 0))</DIV>
<DIV> (define (iter xl)</DIV>
<DIV> (if (not (equal? xl empty))</DIV>
<DIV> (begin</DIV>
<DIV> (add x (car
xl))</DIV>
<DIV> (iter (cdr
xl)))))</DIV>
<DIV> (iter xl)</DIV>
<DIV> (unbox x))</DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<DIV><FONT size=2>-----Original Message----- <BR><B>From:</B> Khorev Sergey
[mailto:Khorev@SoftLab.RU] <BR><B>Sent:</B> ד 29/10/2003 11:47 <BR><B>To:</B>
'plt-scheme@list.cs.brown.edu' <BR><B>Cc:</B> <BR><B>Subject:</B> [plt-scheme]
Boxing in MzScheme<BR><BR></FONT></DIV>
<P><FONT size=2> For list-related administrative tasks:<BR> <A
href="http://list.cs.brown.edu/mailman/listinfo/plt-scheme">http://list.cs.brown.edu/mailman/listinfo/plt-scheme</A><BR><BR>From
manual: "MzScheme provides boxes, which are records that have a
single<BR>field."<BR>I wonder, why one-field record is such important so it
has its own<BR>construction? :))<BR>Or maybe boxing has some special
usage?<BR>I'm knowing about boxing in .NET, where it is used to wrap "simple"
data<BR>types like integers into Object.<BR>Maybe something
similar?<BR><BR>--<BR>Sergey Khorev<BR><A
href="http://iamphet.nm.ru">http://iamphet.nm.ru</A><BR>As between the
skulking and furtive poacher, who hunts for the sake of meat,<BR>and the
honest gentleman shooter, who kills for the pleasure of sport,
I<BR>find<BR>the former a higher type of humanity.<BR> -- Edward
Abbey<BR><BR></FONT></P></BLOCKQUOTE>
</BODY>
</HTML>