listと number(element-at x k)
の 2 つのパラメーターを持つという関数を作成しました。リストの K 番目の要素を返します。x
k
たとえば、式は を(element-at '(a b c d) 3)
返しますc
。次に、 listと number(remove-at x y)
の 2 つのパラメーターを持つ関数が呼び出されます。リストから K 番目の要素を削除します。たとえば、式は を返します。x
k
(remove-at '(a b c d) 3)
(a b d)
(remove-at x y)
I used the function (element-at x k)
but the function will not workの定義で(remove-at x y)
、Dr.racket から「Program run out of memory」と表示されました。だれか理由を知り、できるだけ早く修正できますか?
(define (element-at lis k) (if (null? lis) (if (> k 0) #f '()) (let ((head (car lis)) (tail (cdr lis))) (if (< k 2) head (element-at tail (- k 1))))))
(define (remove-at x y) (let ((first (element-at x y)) (tail x)) (if (equal? (car x) first) (append (remove-at x y) (cdr tail)) (cdr tail))))