[plt-scheme] nested vectors
any way to ask a vector it's length? I tried (length), but it seemed to
complain that I wasn't dealing with a list. seems like a long road to turn
it into a list first. I guess I should look up how to mess with vectors in
scheme. I'm thinking you don't need to pass around the length in the
interface.
On Mon, Feb 16, 2009 at 11:21 AM, Chongkai Zhu <czhu at cs.utah.edu> wrote:
> Yes, this is good (more than acceptable).
>
> Chongkai
>
> e wrote:
>
>> 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 <mailto:
>> 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/c0f5d3ce/attachment.html>