Return to Snippet

Revision: 23537
at February 9, 2010 03:47 by magicrebirth


Initial Code
(let loop ((i 0)
           (j 20) ;; comparison value: it decreases at each recursion (except the first one) 
           (topvalue 20)) ;; komodo value : must be equal to j at the beginning
   (let ((txt "Toyota denies previous banking problem is safety"))
      (if (equal? (- topvalue i) j) ;; the first time
          (loop (+ i 1) j topvalue)
          (begin   (print (substring txt (- topvalue i) j))
                   (if (string=? (substring txt (- topvalue i) j) " ")
                       (string-append (substring txt 0 (- topvalue i)) 
                                      "\n" 
                                      (substring txt (- topvalue i) (string-length txt)))
                       (if (< i topvalue) ;;avoid negative indexes in substring
                           (loop (+ i 1) (- j 1) topvalue)))))))

Initial URL


Initial Description


Initial Title
Scheme: find a substring

Initial Tags


Initial Language
Scheme