[plt-scheme] multi-dimensional arrays

From: Robert Bruce Findler (robby at cs.uchicago.edu)
Date: Sun Dec 8 08:54:42 EST 2002

make-vector puts it's second argument into each place in the array;
since you only created two arrays, you get the second one duplicated in
the first one. You probably meant to use build-vector.

Robby

At Sun, 8 Dec 2002 10:58:14 +0000, Iain Gray wrote:
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> 
> I am attempting to set up a two dimensional array to represent a Hex 
> game board (11 by 11 hexagons).
> 
> My definitions are:-
> 
> (define board (make-vector 11 (make-vector 11 'empty)))
> 
> (define (board-set! row col piece)
>    (vector-set! board row
>                 (vector-set! (vector-ref board row) col piece)))
> 
> with corresponding interactions:-
> 
> Welcome to DrScheme, version 202.
> Language: Textual (MzScheme, includes R5RS).
>  > board
> #11(#0=#11(empty))
>  > (board-set! 5 5 'black)
>  > board
> #11(#0=#11(empty empty empty empty empty black empty) #0# #0# #0# #0# 
> #<void> #0#)
>  >
> 
> My problem is getting a single piece ('black or 'white) written to the 
> board, rather than multiple copies.
> 
> I hope I have not missed something obvious!
> 
> Regards,
> 
> Iain Gray



Posted on the users mailing list.