[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ?

Hi Sam,

this is my simple solution ... propably neither efficient nor
exceptionally elegant but R5RS-compliant and it seems to work. 


PS: Greetings to your teachers.

(define eat-spaces
  (lambda (str)
    (let* ((str str)
           (len (string-length str)))
      (let F ((i 0))
        (cond ((= i len) "")
              ((char-whitespace? (string-ref str i)) (F (+ i 1)))
              (#t (substring str i len)))))))

(define next-word
  (lambda (str)
    (let* ((str (eat-spaces str))
           (len (string-length str)))
      (let F ((i 0))
        (cond ((= i len) (list str ""))
              ((char-whitespace? (string-ref str i)) 
               (list (substring str 0 i)
                     (substring str (+ i 1) len)))
              (#t (F (+ i 1))))))))

(define string->word-list
  (lambda (str)
    (let* ((x (next-word str))
           (word (car x))
           (rest (cadr x)))
       ((= (string-length word) 0) '() )
       ((= (string-length rest) 0) (list word))
       (#t (cons word (string->word-list rest)))))))

   "in the past few weeks I've been investigating")
("in" "the" "past" "few" "weeks" "I've" "been" "investigating")

> hello
> i'm trying to writing a fonction with scheme that can convertir a
> like
> "in the past few weeks I've been investigating"
> to a list containing :
> ("in" "the" "past" "few" "weeks" "i've" "been" "investigating")
> so i will be thinkfull if somebody have the solution.
> sam