Multidimensional vectors in Scheme?

旧街凉风 提交于 2019-12-07 04:11:29

问题


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.


回答1:


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).



来源:https://stackoverflow.com/questions/2954415/multidimensional-vectors-in-scheme

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!