;;;; run.scm (use fox srfi-13) (define-syntax t (syntax-rules (->) ((_ exp -> str) (assert (string=? exp str))))) (t (fox 129.995 -10 '(1)) -> "130.0 ") (t (fox 129.995 10 '(1)) -> " 130.0") (t (fox 129.995 -10. #\* '(1)) -> "**130.0***") (t (fox 129.995 10. #\* '(1)) -> "***130.0**") (t (fox 129.995 10. #\* '(2)) -> "**130.00**") (t (fox 4048 10 #\* '(hexadecimal)) -> "*****#xfd0") (t (fox 4048 10 #\* '(hexadecimal sign)) -> "****#x+fd0") (t (fox 4048 10 #\0 '(hexadecimal sign)) -> "#x+0000fd0") (t (fox 4048.3125 15 #\* '(hexadecimal)) -> "****#i#xfd05/10") (t (fox 4048.3125 15 #\* '(hexadecimal exact)) -> "******#xfd05/10") (t (fox 4048 10 #\0 '(hexadecimal sign) `(,string-upcase . 0)) -> "#X+0000FD0") (t (fox 4048 10 #\Z '(hexadecimal sign) `(,string-upcase . 0)) -> "ZZZZ#X+FD0") (t (fox 4048 10 #\B '(hexadecimal sign) `(,string-upcase . 0)) -> "#X+BBBBFD0") (t (fox 129.995 10 '(2 sign) '("$" . 0)) -> " $+130.00") (t (fox 129.995 10 '(2 sign) '("$" . -3)) -> " $+130") (t (fox 123000000 '(float)) -> "1.23e+8") (t (fox 123000000 '(5 float)) -> "1.23000e+8") (t (fox 1.23456789e+25 '(fixed)) -> "12345678900000000000000000.0") (t (fox 129.995 10. #\* '(0) '("|" . "|")) -> "**|130.|**") (t (fox 129.995 "|" 10. #\* '(0) "|") -> "|***130.***|") (t (fox 123456789.012 '(sign) '#(",")) -> "+123,456,789.012") (t (fox 123456789 '(sign) '#("," 4)) -> "+1,2345,6789") (t (fox "abcdefg" '(sign) '#(",")) -> "abcdefg") (t (fox "abcdefg" '(sign) '#("::" 2)) -> "a::bc::de::fg") (t (fox "abcdefg" '(sign) '#("::" -2)) -> "ab::cd::ef::g") (t (fox '(#\a "str" s)) -> "(a str s)") (t (fox '(#\a "str" s) write) -> "(#\\a \"str\" s)") (t (with-output-to-string (lambda () (fox 'String "^" (current-output-port) 10 #\0 "$"))) -> "^0000String$") (t (with-output-to-string (lambda () (fox 'String "^" #t 10 #\* "$"))) -> "^****String$") (define-record-type example (make-example num str) example? (num get-num set-num!) (str get-str set-str!)) (define (record-writer object string-port) (if (example? object) (begin (display (get-num object) string-port) (display "-" string-port) (display (get-str object) string-port)) (display object string-port))) (define (record-display object string-port) (display (get-num object) string-port) (display "-" string-port) (display (get-str object) string-port)) (t (with-output-to-string (lambda () (let ((plus 12345678.901) (minus -123456.789) (ex (make-example 1234 "ex")) (file "today.txt")) (for-each (lambda (x y) (fox x #t 10) (fox y #t 15 '(2) (if (example? y) record-display display) '#(",")) (fox x #t 10) (fox y #t 15 '(2) record-writer '#(",")) (newline)) (list "plus: " "minus: " "net: " "ex: " "file: ") (list plus minus (+ plus minus) ex file))))) -> " plus: 12,345,678.90 plus: 12,345,678.901 minus: -123,456.79 minus: -123,456.789 net: 12,222,222.11 net: 12,222,222.112 ex: 1234-ex ex: 1234-ex file: today.txt file: today.txt ")