[plt-scheme] nested vectors

From: e (eviertel at gmail.com)
Date: Mon Feb 16 00:04:16 EST 2009

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)

> (array-2d-set! deposits 17 0 11 39)

> (array-2d-ref deposits 17 0 11)

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>

Posted on the users mailing list.