(复制到长度'(a b c)8)
(a b c a b c a b)
(复制到长度'(a b c)2)
(a b)
答案 0 :(得分:2)
好。你定义一个本地程序,并确保你不会隐藏原始参数,以便你可以使用它而不是空列表。
(define (replicate-to-length x i)
(define (replicate-to-length-aux cx i)
...)
;; call helper
(replicate-to-length-aux x i))
或者你可以举起它:
(define (replicate-to-length-aux x cx i)
...)
(define (replicate-to-length x i)
(replicate-to-length-aux x x i))
当然我想这只是为了学习。我会做这样的事情:
#!r6rs
(import (rnrs base)
(only (srfi :1) circular-list take))
(define (replicate-to-length x i)
(take (apply circular-list x) i))