.:HSTuners::::Hondas Wanted:: |
|
|
|
|
#1 |
|
Posts: n/a
|
Some fine scheme code:
; Problem #1, vector-linear-search ; ; vector-linear-search takes a vector (c) and a predicate (pred). It then ; searches through the successive components of v starting from the left end ; and returns the index of the leftmost component of v satisfying pred. If ; no such component is found, it returns -1. ; (define vector-linear-search (lambda (v pred) (let ((size (vector-length v))) (letrec ((helper (lambda (i) (cond ((= i (sub1 size)) (begin (if (apply pred (list (vector-ref v i))) i -1))) ((apply pred (list (vector-ref v i))) i) (else (helper (add1 i))))))) (cond ((zero? size) -1) (else (helper 0))))))) Ahh Bryan |
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|