(旋转'(a b c d e))应该返回((a b c d e)(b c d e a)(c d e b)(d e a b c)(e a b c d))
这里我已经在shceme中实现了逻辑,但我遇到了问题,任何人都可以帮我解决这个问题
这是我的代码
(define (rotate lst)
(define (iter l cycles result)
(cond
((= cycles 0) (cons lst result))
((< cycles 0) result)
(else (let ((cycled (cycle l)))
(iter cycled (- cycles 1) (append result (list cycled)))))))
(iter lst (- (length lst) 1) ()))
(rotate '(a b c d e))
答案 0 :(得分:0)
你不是那么远:
(define (rotate lst)
(define (iter lst cycles res)
(cond
((= cycles 0) (reverse res))
(else (iter (append (cdr lst) (list (car lst)))
(- cycles 1)
(cons lst res)))))
(iter lst (length lst) null))
(cycle l)
?是否在其他地方定义了?