Jim Hoang <jimh@intergate.bc.ca> 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:
http://www.cs.rice.edu/CS/PLT/packages/doc/mzscheme/node32.htm
Of course, if your assignment says you simply *must* have a "make-box",
then try this:
(define (make-box . initial-value)
(cond
((null? initial-value)
(box (void)))
((null? (cdr initial-value))
(box (car initial-value)))
(else
(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].
-Rob
[*] I keep forgetting the name "unbox" (*blush*)
so I sometimes alias it to "box-ref". ;-}
-----
Rob Warnock, 8L-855 rpw3@sgi.com
Applied Networking http://reality.sgi.com/rpw3/
Silicon Graphics, Inc. Phone: 650-933-1673
2011 N. Shoreline Blvd. FAX: 650-933-0511
Mountain View, CA 94043 PP-ASEL-IA