Next: formations escape char, Previous: formations output, Up: formations [Index]
Object output. Parameters: minwidth, padinc, minpad, padchar.
~a
outputs an argument like display
, ~s
outputs an argument like write
.
(format #t "~a" "foo") -| foo (format #t "~s" "foo") -| "foo"
~:a
and ~:s
put objects that don’t have an external
representation in quotes like a string.
(format #t "~:a" car) -| "#<primitive-procedure car>"
If the output is less than minwidth characters (default 0), it’s
padded on the right with padchar (default space). ~@a
and ~@s
put the padding on the left instead.
(format #f "~5a" 'abc) ⇒ "abc " (format #f "~5,,,'-@a" 'abc) ⇒ "--abc"
The number of padding characters, padchar, included in the output is computed with: minpad + N * padinc, where n is the smallest integer making the total object plus padding greater than or equal to minwidth. The default minpad is 0 and the default padinc is 1 (imposing no minimum or multiple).
(format #f "~5,1,4a" 'abc) ⇒ "abc "
More examples:
(import (except (vicare) format) (vicare formations)) (format #f "ciao ~:a" display) ⇒ "ciao \"#<procedure display>\"" (format "~5a" 123) ⇒ "123 " (format "~5s" 123) ⇒ "123 " (format "~5@a" 123) ⇒ " 123" (format "~5@s" 123) ⇒ " 123" (format "~5,,,'.a" 123) ⇒ "123.." (format "~5,,,'.s" 123) ⇒ "123.." (format "~5,,,'.@a" 123) ⇒ "..123" (format "~5,,,'.@s" 123) ⇒ "..123" (format "~5,,4,'.@a" 123) ⇒ "....123" (format "~5,,4,'.@s" 123) ⇒ "....123" ;;; 1234 (format "~10,,,'a@a" 123) ⇒ "aaaaaaa123" (format "~10,,,'a@s" 123) ⇒ "aaaaaaa123" ;;; 1234567 (format "~10,3,,'u@a" 123) ⇒ "uuuuuuuuu123" (format "~10,3,,'u@s" 123) ⇒ "uuuuuuuuu123" ;;; 123456789 (format "~11,2,,'u@a" 123) ⇒ "uuuuuuuu123" (format "~11,2,,'u@s" 123) ⇒ "uuuuuuuu123" ;;; 12345678 (format "~8,2,,'u@a" 1) ⇒ "uuuuuuuu1" (format "~8,2,,'u@s" 1) ⇒ "uuuuuuuu1" ;;; 12345678
Next: formations escape char, Previous: formations output, Up: formations [Index]