; camel case

(define (camel-case->underscore str)
  (let loop ((cs (string->list str)) (zs (list)))
    (if (null? cs) (list->string (reverse zs))
      (if (char-upper-case? (car cs))
          (loop (cdr cs) (cons (char-downcase (car cs)) (cons #\_ zs)))
          (loop (cdr cs) (cons (car cs) zs))))))

(define (underscore->camel-case str)
  (let loop ((cs (string->list str)) (zs (list)))
    (if (null? cs) (list->string (reverse zs))
      (if (char=? (car cs) #\_)
          (if (null? (cdr cs)) (list->string (reverse zs))
            (loop (cddr cs) (cons (char-upcase (cadr cs)) zs)))
          (loop (cdr cs) (cons (car cs) zs))))))

(display (camel-case->underscore "camelCaseToUnderscore")) (newline)
(display (underscore->camel-case "underscore_to_camel_case")) (newline)