binarysearch.scm
1 2 ; Andrew Pennebaker 3 ; 18 Feb 2007 4 ; License: GPL 5 ; URL: http://snippets.dzone.com/posts/show/3535 6 7 (define binary-search 8 (lambda (ls value low high) 9 (let ((mid (floor (/ (+ low high) 2)))) 10 (cond 11 ((> low high) -1) 12 ((= (list-ref ls mid) value) mid) 13 ((> (list-ref ls mid) value) (binary-search ls value low (- mid 1))) 14 ((< (list-ref ls mid) value) (binary-search ls value (+ mid 1) high))))))