If I have a list like this
(1 2 3) And I want to find the index of 2,I used the function
(position '3 '(1 2 3))
when compiling this error was occurred
. . position: undefined; cannot reference undefined identifier
If I understand you correctly, you simply want to find the index of an element in a list. I haven't found a build-in procedure for this, but you can do this easily yourself:
(define (position elt lst)
(let loop ((lst lst) (i 0))
(cond
((null? lst) #f)
((eq? elt (car lst)) i)
(else (loop (cdr lst) (+ 1 i))))))
then
(display (position '3 '(1 2 3)))
=> 2