dimanche 19 avril 2015

Scheme: How to find a position of a char in a string

I am trying to find the index of a string where it is equal to a certain character, but I can seem to figure it out. This is what I got so far, but its not working...



`(define getPos


(lambda () (define s (apply string-append myList)) (getPosition pos (string->list s))))



(define getPosition
(lambda (position s)
(if (and (< position (length s)) (equal? (car s) #\space))
((set! pos (+ pos 1)) (getPosition (cdr s) pos));increment the positon and continue the loop
pos;else
)


) )


(define length (lambda (s);the value s must be coverted to a string->list when passed in (cond ((null? s) 0) (else (+ 1 (length (cdr s)))) ) ) )


Aucun commentaire:

Enregistrer un commentaire