Return to Snippet

Revision: 4657
at January 14, 2008 18:34 by gleather


Initial Code
(define list-index
        (lambda (s los)
                (if (null? los)
                        -1
                        (if (eq? (car los) s)
                                0
                                (if (= (list-index s (cdr los)) -1) 
                                        -1
                                        (+ 1 (list-index s (cdr los))))))))

Initial URL


Initial Description
This one drove me crazy because of the requirement to return -1 if s not in los.

(list-index s los) returns the zero-based index of the first
occurence of s in los, or -1 if there is no occurences of s in los.

Initial Title
list-index (Scheme)

Initial Tags


Initial Language
Lisp