[plt-scheme] create a board with vector

From: Mona (mona.esmaili at gmail.com)
Date: Fri Dec 4 17:30:23 EST 2009

Hi,I want to create a board with size n x n but I dont know what is
the problem it doesn't work.

(define a-tile #t)

; a row is a vector of tiles: (vectorof tile)
(define a-row (vector #t #t #t #t))

; a board is a vector of rows: (vectorof (vectorof tile))
(define board8x8 (vector (vector #t #t #t #t #t #t #t #t)
                          (vector #t #t #t #t #t #t #t #t)
                          (vector #t #t #t #t #t #t #t #t)
                          (vector #t #t #t #t #t #t #t #t)
                          (vector #t #t #t #t #t #t #t #t)
                          (vector #t #t #t #t #t #t #t #t)
                          (vector #t #t #t #t #t #t #t #t)
                          (vector #t #t #t #t #t #t #t #t)))

; build-board: N (N N => boolean) => board
; to create a board of size n x n
; fill each position with indices i and j with (f i j)
(define build-board
  (lambda (n f)
    (build-vector n
                  (lambda(j)
                      (build-vector n
                                    (lambda (i)
                                      (f i j)))))))

; board-ref: board N N = boolean
; to access a position with indices i, j on a-board
(define board-ref
  (lambda (a-board i j)
   (vector-ref (vector-ref a-board i) j)))


Thank you
Mona


Posted on the users mailing list.