In: Computer Science
Use Scheme Language
Write a Scheme function that takes a list and returns a list identical to the parameter except the third element has been deleted. For example, (deleteitem '(a b c d e)) returns ‘(a b d e) ; (deleteitem '(a b (c d) e)) returns ‘(a b e).
Code to Copy;
(define (deleteitem list)
(unless (or (null? list)
(null? (cdr list))
(null? (cddr list)))
(set-cdr! (cdr list) (cdddr
list)))
list)
(display (deleteitem '(a b c d e)))
(display (deleteitem '(1 2 3 4 5)))
(display (deleteitem '(a b (c d) e)))
Output Screenshots:
i). output for (display (deleteitem '(a b c d e)))
ii). output for (display (deleteitem '(1 2 3 4 5)))
iii). output for (display (deleteitem '(a b (c d) e)))