Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started