尝试从方案中的列表中获取元素的索引
所以我试图从列表中获取索引 ex:
(get-indices 'G (list 'A 'G 'T 'X 'I 'T 'G))
(2 7)
其中索引从 1 开始,所以 ' A 是索引一
我正在考虑使用辅助函数,它需要 elt lst 和索引 ex: (get-indices-helper el lst index)
我也在考虑可能使用 list-ref 并喜欢切换它以使其以获取索引的方式工作,但是我找不到它的实际方案定义。
So i'm trying to get the indices from a list ex:
(get-indices 'G (list 'A 'G 'T 'X 'I 'T 'G))
(2 7)
where the index starts at 1 so 'A is index one
I was thinking on using a helper function where it takes an elt lst and index
ex: (get-indices-helper el lst index)
I was also thinking about possibly using list-ref and like switching it to make it work in the get indices way however i could not find the actual scheme definition for it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编写一个函数,递归输入列表,跟踪它正在查看的元素的位置,并使用
cons
发出匹配索引。这实在是微不足道的事;我想这是一个你被设置为家庭作业的问题?使用 GNU Guile 或 MzScheme 或其他东西对此进行测试:
打印:
耶!
Write a function that recurses down the input list, keeping track of the position of the element that it's looking at, and emitting the matching indexes with
cons
. This is really trivial; I assume that it is a question that you have been set as homework?Testing this with GNU Guile or MzScheme or something:
Prints:
Yay!