; File: list-position.scm ; Title: Find the first position of w in a list(as vector) ;> (list-position 2 '( 9 3 4 2))-> 3 ;> (list-position 2 '( 9 3 4 5))-> #f ;> (list-position 2 '(2 9 3 4 5))-> 0 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (list-position w L) (let loop ((i 0) (r L)) (cond ((null? r) #f) ((equal? (car r) w) i) (else (loop (+ i 1) (cdr r))) ))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (list-position2 w L) (cond ((not (member w L)) #f) ((equal? (car L) w) 0) (else ( + 1 (list-position2 w (cdr L)))) ))