views:

81

answers:

1

I earlier asked a question about arrays in scheme (turns out they're called vectors but are basically otherwise the same as you'd expect).

Is there an easy way to do multidimensional arrays vectors in PLT Scheme though? For my purposes I'd like to have a procedure called make-multid-vector or something.

By the way if this doesn't already exist, I don't need a full code example of how to implement it. If I have to roll this myself I'd appreciate some general direction though. The way I'd probably do it is to just iterate through each element of the currently highest dimension of the vector to add another dimension, but I can see that being a bit ugly using scheme's recursive setup.

Also, this seems like something I should have been able to find myself so please know that I did actually google it and nothing came up.

+3  A: 

The two common approaches are the same as in many languages, either use a vector of vectors, or (more efficiently) use a single vector of X*Y and compute the location of each reference. But there is a library that does that -- look in the docs for srfi/25, which you can get with (require srfi/25).

Eli Barzilay
Thanks - you've been very helpful with all these scheme questions :). I think for now I'll go with the X*Y solution, as it will be easy to implement and efficient, and will be fine for what I need it for. In the future if I need to do this for more complex situations, I'll look into srfi/25.
Cam
You can always look at the implementation -- see how it's done so you can do something similar.
Eli Barzilay
You mean look at the srfi/25 implementation to see how they did it? I already have a pretty good idea of what I need to do in order to get this working, but I'll definitely peek if I hit a mental roadblock!
Cam