/usr/lib/s9fes/string-translate.scm is in scheme9 2010.11.13-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | ; Scheme 9 from Empty Space, Function Library
; By Nils M Holm, 2010
; See the LICENSE file of the S9fES package for terms of use
;
; (string-translate string1 string2 string3) ==> string
;
; Translate STRING1 by replacing each instance of a character
; that occurs in STRING2 by the character at the corresponding
; position in STRING3. STRING-TRANSLATE does not alter STRING1
; but returns a fresh string.
;
; Example: (string-translate "a:b:c" ":" "-") ==> "a-b-c"
;
; (string-translate
; "hello, world!"
; "abcdefghijklmnopqrstuvwxyz"
; "nopqrstuvwxyzabcdefghijklm") ==> "uryyb, jbeyq!"
(define (string-translate s from to)
(let* ((k (string-length s))
(kf (string-length from))
(x (string->list from))
(new (string-copy s)))
(let loop ((i 0))
(cond ((>= i k)
new)
((memv (string-ref s i) x)
=> (lambda (u)
(string-set! new
i
(string-ref to (- kf (length u))))
(loop (+ 1 i))))
(else
(loop (+ 1 i)))))))
|