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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!