lambdamusic
2/7/2013 - 9:28 PM

Scheme: scheme: replace a string

Scheme: scheme: replace a string

(define string-replace 
   (lambda (s match replacement)
      (let ((ll (string->list s))
            (match1 (char match))
            (replacement1 (char replacement)))
         (if (= (string-length match) 1)
             (let ((z (map (lambda (x)
                              (if (equal? x match1)
                                  replacement1
                                  x))
                           ll)))
                (list->string (list-flatten z)))
                ;z)
             (print "i can match only single characters for now")))))