The last line of my code should returns the index of the first location where atm occurs in the list. for example (list-memeber? 9 '(4 9 3 6 8)) should return 2, but it gives me length + 1. Length + 1 should only work when atm doesn't occur in the list. How could I do that?
(define (list-length l)
(if (null? l)
0
(+ 1 (list-length (cdr l)))))
(define (list-memeber? atm lst)
(cond
((null? lst) '() ) ;returns null if list is empty (This part works fine)
((not (eq? atm (car lst))) (+ 1 (list-length lst))) ;If atm does not occur in the list, the function returns length + 1 ((This works fine)
((eq? atm (car lst)) 1) ;if fisrt element equals atm, function returns location which is 1 (This also works fine)
(else (+ 1 (list-memeber? atm (cdr lst)))))) ;here is where I'm having problem. This should return location of index where atm occurs.