[plt-scheme] nested vectors
is something like this an acceptable approach? (just teat a linear array
like a 2d array). seems like a better version of this stuff is probably
part of the included stuff, I would imagine. Like there's probably a way to
get the size of a vector. I was going to make a (array-2d-print) function,
too that displays it like a grid ..... maybe tomorrow. Any suggested
improvements or directions are of course welcome.
(define (make-array-2d size initial)
(make-vector (* size size) initial))
(define (array-2d-ref array size row col)
(vector-ref array (+ (* row size) col)))
(define (array-2d-set! array size row col value)
(vector-set! array (+ (* row size) col)))
> (define deposits (make-array-2d 17 0))
> (array-2d-ref deposits 17 0 11)
0
> (array-2d-set! deposits 17 0 11 39)
> (array-2d-ref deposits 17 0 11)
39
On Sat, Feb 14, 2009 at 4:40 PM, Chongkai Zhu <czhu at cs.utah.edu> wrote:
> and every slot of the vector is filled with `fill'. In your
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20090216/552ed95a/attachment.html>