summaryrefslogtreecommitdiff
path: root/Alpha/String.scm
blob: 779c2fb202fa0ff1e3c0f6fed666be995229557b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
(define-module (Alpha String)
  #:export (replace to-string str capitalize))

(define (replace s match repl)
  (let ((f (lambda (a b)
             (let ((next-char (if (eq? a match) repl a)))
               (string-concatenate (list b (string next-char)))))))
    (string-fold f "" s)))

(define (to-string x)
  (format #f "~a" x))

(define str
  (case-lambda
    (() "")
    ((x) (to-string x))
    ((x . rest) (string-concatenate (map str (cons x rest))))))

(define (capitalize s)
  (let ((s (to-string s)))
    (if (< (string-length s) 2)
        (string-upcase s)
        (str (string-upcase (substring s 0 1))
             (substring s 1 )))))