Scheme中的多维向量? [英] Multidimensional vectors in Scheme?

查看:45
本文介绍了Scheme中的多维向量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我之前问过一个关于scheme中的数组的问题(原来它们被称为向量,但基本上与您期望的相同).

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

有没有一种简单的方法可以在 PLT Scheme 中处理多维 arrays 向量?出于我的目的,我想要一个名为 make-multid-vector 或其他东西的过程.

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.

推荐答案

这两种常见的方法在很多语言中都是一样的,要么使用向量的向量,要么(更有效地)使用 X*Y 和计算每个参考的位置.但是有一个库可以做到这一点 - 查看 srfi/25,你可以通过 (require srfi/25) 获得.

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

这篇关于Scheme中的多维向量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆