Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
无法弄清楚我的功能中的错误。它应该在列表中循环 n 次,例如:
cycle([1, 2, 3, 4, 5, 6], 2)将返回[3, 4, 5, 6, 1, 2],循环列表两次。
cycle([1, 2, 3, 4, 5, 6], 2)
[3, 4, 5, 6, 1, 2]
这是我的代码,但我想我正在进入一个无限递归循环。有什么帮助吗?
fun cycle (a, n) = if n >= 0 then cycle (cycle1 a, n-1) else cycle (a, n-1);
当 n < 0 时,您会继续循环。为了防止无限循环,请不要这样做。(另外,当 n = 0 时,您可能不想循环 1。)