Question: Write a recursive Dr. Racket function first_n of two arguments(an integer n and a list L) to do the following: Return the first n>=0 elements
Write a recursive Dr. Racket function first_n of two arguments(an integer n and a list L) to do the following:
Return the first n>=0 elements of list L. Assume the list elements are numbered from 1 to N (where N>=0 equals the length of the list).
If n is out of range, return an error message:
(first-n 1 '(a b c d)) returns '(a)
(first-n 4 '(a b c d)) returns '(a b c d)
(first-n 1 '((a) b c d)) returns '((a))
(first-n 2 '(((a))( b c d))) returns '(((a))(b c d))
(first-n 0 '((2 3)(5 6)(4 4)(3 3))) returns '( )
(first-n 3 '(2 3)) returns an error message
(first-n 0 '( )) returns '( )
Run at least 10 different test cases(including the above 7) on your program.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
