; titlecase

(define (char-alphanumeric? c)
  (or (char-alphabetic? c) (char-numeric? c)))

(define (titlecase str)
  (let ((str (string-downcase str)) (inword #f))
    (do ((i 0 (+ i 1))) ((= i (string-length str)) str)
      (if inword
          (when (char-whitespace? (string-ref str i))
            (set! inword #f))
          (when (and (char-alphanumeric? (string-ref str i))
                     (or (zero? i)
                         (not (char-alphanumeric? (string-ref str (- i 1))))))
            (set! inword #t)
            (string-set! str i (char-upcase (string-ref str i))))))))

(display (titlecase "programming PRAXIS")) (newline)
(display (titlecase "\"prax'is\"")) (newline)
(display (titlecase "123p")) (newline)