Next: , Previous: , Up: srfi intermediate-format   [Index]


2.25.5 Examples

(format "Hello, ~a" "World!")
⇒ "Hello, World!"

(format "Error, list is too short: ~s" '(one "two" 3))
⇒ "Error, list is too short: (one \"two\" 3))"

(format "test me")
⇒ "test me"

(format "~a ~s ~a ~s" 'this 'is "a" "test")
⇒ "this is a \"test\""

(format #t "#d~d #x~x #o~o #b~b~%" 32 32 32 32)
-| #d32 #x20 #o40 #b100000
⇒ #<unspecified>

(format "~a ~? ~a" 'a "~s" '(new) 'test)
⇒ "a new test"

(format #f "~&1~&~&2~&~&~&3~%")
⇒ "
1
2
3
"

(format #f "~a ~? ~a ~%" 3 " ~s ~s " '(2 2) 3)
⇒ "3  2 2  3
"

(format "~w" (let ( (c '(a b c)) ) (set-cdr! (cddr c) c) c))
⇒ "#1=(a b c . #1#)"

(format "~8,2F" 32)
⇒ "   32.00"

(format "~8,3F" (sqrt -3.8))
⇒ "0.000+1.949i"

(format "~8,2F" 3.4567e11)
⇒ " 3.45e11"

(format "~6,3F" 1/3)
⇒ " 0.333"

(format "~4F" 12)
⇒ "  12"

(format "~8,3F" 123.3456)
⇒ " 123.346"

 (format "~6,3F" 123.3456)
⇒ "123.346"

 (format "~2,3F" 123.3456)
⇒ "123.346"

(format "~8,3F" "foo")
⇒ "     foo"

(format "~a~a~&" (list->string (list #\newline)) "")
⇒ "
"