I have to write a recursive call in Racket that allows us to get the Nth position of a given list. for example (getNth 3 '(1 2 3 4)) should return back 4 and if the list is empty or if the position is non existent then return and empty list.
this is my code:
(define getNth
(lambda (ls)
(if (= ls null?) 1
(getNth ls(append '(car ls)(cdr ls))))))
getting this error: getnth: arity mismatch; the expected number of arguments does not match the given number expected: 1 given: 2 arguments...: 4 ()
if you need the recursive statement here it is:
base case-getNth N LS) = (), if LS = null
recursive call -(getNth N LS) = (getNth N (append '(car LS)(cdr LS))), if N >= 1
im getting stumped I dont know how to implement this one.