0
刪除每第n個項試圖在方案刪除每第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)
>