Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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)))))))
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote