cl:string-replace   scheme


Defined in:  https://github.com/lambdamusic/extempore-extensions/blob/main/init/init_lisp.xtm

Implementation

;; matches a single character in a string, and replaces it
(define cl:string-replace 
   (lambda (s match replacement)
      (let ((ll (string->list s))
            (match1 (cl:char match))
            (replacement1 (cl:char replacement)))
         (if (= (string-length match) 1)
             (let ((z (map (lambda (x)
                              (if (equal? x match1)
                                  replacement1
                                  x))
                           ll)))
                (list->string (cl:list-flatten z)))
                ;z)
             (print "i can match only single characters for now")))))


Back to Index