Question: Function nth in lisp takes two arguments (a list I, and an integer n), and returns the nth element of the list I. Implement your
Function nth in lisp takes two arguments (a list I, and an integer n), and returns the nth element of the list I.
Implement your own version of nth, called my-nth, as in the above.
Note that to access the elements of a list you are only allowed to use CAR and CDR functions.
Examples:
> (my-nth O'(a b c d)) ; returns A, as A is at 0th index.
> (my-nth 2 '(a b c d)); returns C
> (my-nth 4 '(a b c d)); returns NIL (out of bound)
> (my-nth -1 '(a b c d)); returns NIL (out of bound)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
