It\'s a LISP Programming problem please help me! I need to make remove-2nd funct
ID: 3804716 • Letter: I
Question
It's a LISP Programming problem please help me!
I need to make remove-2nd function!
The result must be like this!!
(remove-2nd ‘a ’(b a n a n a)) => (b a n n a)
(remove-2nd ‘a ’(b (a n) a n a) => (b (a n) a n)
(remove-2nd ‘(1 2) ’(1 2 (1 2) 3)) => (1 2 (1 2) 3)
i made the code like this...
(defun remove2nd (x y)
(if (null y)
'()
(if(eq x (car y))
(setq mycount (+ mycount 1))
(if(eq mycount 2)
(remove2nd x (cdr y))
(cons(car y) (remove2nd x (cdr y))))
(cons(car y) (remove2nd x (cdr y))))))
But it doesn't work.... help me
Explanation / Answer
Answer:
(define remv-1st (lambda (x ls) (cond ((null? ls) '()) ((eq? x (car ls)) (cdr ls)) (else (cons (car ls) (remv-1st x (cdr ls)))))))Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.