(module pad scheme/base ;;; To my knowledge Scheme's (format) function does not allow for ;;; specifying field width or alignment. The functions in this ;;; module can be used to pad and align a string destined for ;;; (format). (provide pad-left pad-right) (define (pad-left obj n . [(c #\space)]) "Return the string representation of the object OBJ padded with character C and left aligned." (let* ((s (format "~a" obj)) (len (string-length s)) (needed (max 0 (- n len)))) (string-append s (make-string needed c)))) (define (pad-right obj n . [(c #\space)]) "Return the string representation of the object OBJ padded with character C and right aligned." (let* ((s (format "~a" obj)) (len (string-length s)) (needed (max 0 (- n len)))) (string-append (make-string needed c) s))) )