The answer was simpler than you expected, and also without recursion :)
Simple function if you are sure that the item is in the list
(define element-index (lambda (elemento lista) (- (length lista) (length (memv elemento lista)))))
If you are considering a case where an item may not be in the list. Return false if not found
(define element-index (lambda (elemento lista) (if (eqv? (list? (memv elemento lista)) #t) (- (length lista) (length (memv elemento lista))) false ) ))
Final result:
> (element-index 2 '(2 3 4 5)) 0 > (element-index 4 '(2 3 4 5)) 2 > (element-index 6 '(2 3 4 5)) false
source share