[racket] how can I change only one element in the vector?

From: Neil Van Dyke (neil at neilvandyke.org)
Date: Sat Nov 20 03:44:20 EST 2010

김태윤 wrote at 11/20/2010 03:31 AM:
> thank you !
> could you tell me how to make new vector that does not refer to a 
> single vector?

"make-vector" is not the correct way, but there are many other ways.

This will make the nested vectors like you originally intended:

(vector (vector (vector 1 2 3)
                (vector 1 2 3))
        (vector (vector 1 2 3)
                (vector 1 2 3)))

You can also use procedures:

(define (make-xyz) (vector (make-yz) (make-yz)))
(define (make-yz)  (vector (make-z)  (make-z)))
(define (make-z)   (vector 1 2 3))
(make-xyz)

Or, if you want to represent multiple dimensions, and you know the size 
of each dimension, you can use a single vector and then do arithmetic of 
the X, Y, Z to find the right index:

(vector 1 2 3 1 2 3 1 2 3 1 2 3)


-- 
http://www.neilvandyke.org/


Posted on the users mailing list.