【发布时间】:2016-05-23 19:02:26
【问题描述】:
尝试递归删除方案中的每第 n 个项目
(define x '(1 2 3 4 5 6 7 8 15 10))
(define ndelete
(lambda (alist nth) ;@params (list to delete items from) (nth intervals to delete items)
(cond [(null? alist) alist] ;if null, return empty list
[(if (= nth 1) (ndelete (cdr alist) nth))]
[else (list (car alist) (ndelete (cdr alist) (- nth 1)))]
)))
当我打电话时:
> (ndelete x 5)
输出应该是:
(1 2 3 4 6 7 8 15)
但我得到空白输出:
> (ndelete x 5)
>
【问题讨论】: