[plt-scheme] nested vectors
On Feb 14, wooks wrote:
> working in Pretty Big
>
> (define deposits (make-vector 17 (make-vector 17)))
>
> Now I want to set the value of the index entry [0,11] in deposits to
> 39.
>
> (vector-set! (vector-ref deposits 0) 11 39) gives a weird result.
> Please explain the result and correct me.
What you did is similar to
(define deposits
(let ([row (vector 1 2 3)])
(vector row row row)))
but what you reaaly need is to have separate vectors for each row:
(define deposits
(vector (vector 1 2 3) (vector 1 2 3) (vector 1 2 3)))
You probably want something like
(build-vector 17 (lambda (_) (make-vector 17)))
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://www.barzilay.org/ Maze is Life!