LISP 초보자는 여기에 있습니다. 나는 LISP에서의 다가오는 시험을 준비하고 있으며, 해결할 수없는 문제를 만났습니다. 그래서 더 많은 경험을 가진 사람이 나를 도울 수 있기를 바랬습니다.목록이 포함 된 목록의 요소 삭제
어쨌든, 여기 내 문제가 있습니다 : 목록을 요소로 포함 할 수있는 목록이 제공됩니다. 당신의 임무는 주어진 위치에 원자 원소를 삭제하는 것입니다.
목록 및 위치는 입력 매개 변수로 제공됩니다.
예 : Position = 5, List = (1 (2 3) ((4)) (5 (6)))는 (1 (2 3) ((4)) (.
여기는 내가 지금까지 가지고있는 것입니다 ... (PS 코드는 imMaw의 도움 덕분에 작동합니다. 이전 실수를보기 위해 편집을 확인할 수 있습니다).
(defun number_of_atoms(List)
(atoms List 0)
)
(defun atoms(List Number)
(cond
((null List) Number)
((atom (car List)) (atoms (cdr List) (+ 1 Number)))
((+ (atoms (car List) Number) (atoms (cdr List) 0)))
)
)
(defun deleteElement(Pos List)
(deleteElementAcc Pos 1 List)
)
(defun deleteElementAcc(Pos CurrPos List)
(cond
((null List) nil)
((and (atom (car List)) (not(eql CurrPos Pos))) (cons (car List) (deleteElementAcc Pos (+ CurrPos 1) (cdr List))))
((and (atom (car List)) (eql CurrPos Pos)) (deleteElementAcc Pos (+ CurrPos 1) (cdr List)))
((cons (deleteElementAcc Pos CurrPos (car List))
(deleteElementAcc Pos (+ CurrPos (number_of_atoms(car List))) (cdr List))))
)
)
좋아, 문제는 무엇인가 :
시도
는 순환 목록이나 중복을 식별하기 위해 만들어졌다? –@RainerJoswig 게시 한 문제를 해결하는 방법을 알고 싶습니다. – ssBarBee
확실하지만 코드가 수행 중이거나하지 않는 작업은 무엇입니까? –