Please write a full answer 1) a) Write a Scheme using DrRacket function called p
ID: 3745474 • Letter: P
Question
Please write a full answer
1) a) Write a Scheme using DrRacket function called penultimate that takes a list, which must contain more than one value, and returns the second-last t value in the list. For example, the penultimate '(1 2 3)) returns 2. to) Write a Scheme function using DrRacket called remove-penultimate that takes a list of numbers, which must contain more than one value, and returns the list of all values except the second-last in the list For example, the result (remove-penultimate '(1 2 3)) returns (1 3)Explanation / Answer
1 a)
The function to return the last second element of the list is
(define (penultimate lst n)
if(zero? n)
(car lst)
(penultimate (cdr lst) (- n 1)))
call the function by passing the elements of the list
(penultimate (list 1 2 3) 1)
Function to get all the elements except second last element
(define (remove-penultimate lst n)
if(zero? n)
(car lst)
(remove-penultimate (cdr lst) (- n 1)))
(first remove-penultimate (list 1 2 3) 1)
(rest remove-penultimate (list 1 2 3) )