Question: 5. Build a LISP function called filter-negatives as follows: This function takes a list of numbers as an argument and returns that list with any
5. Build a LISP function called filter-negatives as follows: This function takes a list of numbers as an argument and returns that list with any negative numbers removed. It recursively examines each element of the list; If the first element is negative, it is discarded and the function returns the result of filtering the negative numbers from the cdr of the list. If the first element of the list is positive, it is consed onto the result of filtering negatives from the rest of the list. Test your program with the following data: > (filter-negatives '(1 -1 2 -2 3 -3)) (1 2 3) > (filter-negatives '(-1 -2 -3 -4 -5)) empty
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
