Subject: Re: Please help!
From: (Rob Warnock)
Date: 1999/04/30
Newsgroups: comp.lang.scheme
Message-ID: <7gb66i$>
Jim Hoang <> wrote:
| I am using the popular Dr. Scheme to work on an assignment that requires
| boxes and mass mutations. However, the make-box command does not seem to
| work.... can I fix this?

I know it probably seems like there ought to be such a beast as "make-box",
by analogy to (vector item1 item2 ... itemN) and (make-vector size init-val),
but since boxes can only hold one value/object, there's really little
point in having a "make-box" distinct from just "(box value)", so MzScheme
[the implementation underneath DrScheme] doesn't provide one -- just "box",
"unbox"[*], "set-box!", and "box?".  See:

Of course, if your assignment says you simply *must* have a "make-box",
then try this:

	(define (make-box . initial-value)
	    ((null? initial-value)
	     (box (void)))
	    ((null? (cdr initial-value))
	     (box (car initial-value)))
	     (error "make-box requires zero or one argument(s)"))))

By the way, boxes aren't the only thing that breaks that neat
(foo args...)/(make-foo) pattern -- there's no "make-pair" other
than "cons" either [unless you make one yourself, as above].


[*] I keep forgetting the name "unbox" (*blush*)
so I sometimes alias it to "box-ref".  ;-}

Rob Warnock, 8L-855
Applied Networking
Silicon Graphics, Inc.		Phone: 650-933-1673
2011 N. Shoreline Blvd.		FAX: 650-933-0511
Mountain View, CA  94043	PP-ASEL-IA