aladdin wrote:
I had a problem when using vector-fill! to fill a dimension of 2D array.
Here is my code. Please note the second section of the code. First it
generate a 2x2 array with nested make-vector. Then, it called
vector-fill! to fill the second row of the array with value 10. But it
turns out that the whole 2x2 array is filled with 10.
Running the code under mzscheme works out the same result. Is it a bug?
Or is there something wrong with my code?
Something is wrong with your code. Consider this:
(define v '#(#(1 3) #(2 4)))
(display v)(newline)
(vector-fill! (vector-ref v 1) 10)
(display v)(newline)
(set! v (make-vector 2 (make-vector 2 1)))
Make-vector is a function. That means the above line is equivalent to:
(set! v (let ((b (make-vector 2 1)))
(make-vector 2 b)))
Make-vector doesn't know how to copy every object, so they assume you
want *the same object* in each position. Try it out with pairs:
(let ((v (make-vector 2 (list 1))))
(write v)
(newline)
(set-car! (vector-ref v 0) 42)
(write v)
(newline))
--
;;; Stephen Compall ** http://scompall.nocandysw.com/blog **
But you know how reluctant paranormal phenomena are to reveal
themselves when skeptics are present. --Robert Sheaffer, SkI 9/2003
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user