问题描述
sash> (remove-at '(a b c d) 2)
-> (a c d)
解法
(define remove-at
(lambda (ls k)
(let f ([i 1] [s ls])
(cond
[(null? s) '()]
[(= i k) (cdr s)]
[else (cons (car s) (f (+ i 1) (cdr s)))]))))
sash> (remove-at '(a b c d) 2)
-> (a c d)
(define remove-at
(lambda (ls k)
(let f ([i 1] [s ls])
(cond
[(null? s) '()]
[(= i k) (cdr s)]
[else (cons (car s) (f (+ i 1) (cdr s)))]))))