0000: 0a 5c 74 69 74 6c 65 7b 43 6f 6d 62 69 6e 61 74 .\title{Combinat
0010: 6f 72 20 46 6f 72 6d 61 74 74 69 6e 67 7d 0a 0a or Formatting}..
0020: 5c 65 76 61 6c 0a 28 62 65 67 69 6e 0a 20 20 28 \eval.(begin. (
0030: 64 69 73 70 6c 61 79 20 22 3c 73 74 79 6c 65 3e display "<style>
0040: 5c 6e 22 29 0a 20 20 28 64 69 73 70 6c 61 79 20 \n"). (display
0050: 28 77 69 74 68 2d 69 6e 70 75 74 2d 66 72 6f 6d (with-input-from
0060: 2d 66 69 6c 65 20 22 66 6d 74 2e 63 73 73 22 20 -file "fmt.css"
0070: 72 65 61 64 2d 73 74 72 69 6e 67 29 29 0a 20 20 read-string)).
0080: 28 64 69 73 70 6c 61 79 20 22 3c 2f 73 74 79 6c (display "</styl
0090: 65 3e 5c 6e 22 29 29 0a 0a 5c 66 6c 75 73 68 72 e>\n"))..\flushr
00a0: 69 67 68 74 7b 5c 75 72 6c 68 7b 68 74 74 70 3a ight{\urlh{http:
00b0: 2f 2f 73 79 6e 74 68 63 6f 64 65 2e 63 6f 6d 2f //synthcode.com/
00c0: 7d 7b 41 6c 65 78 20 53 68 69 6e 6e 7d 7d 0a 5c }{Alex Shinn}}.\
00d0: 66 6c 75 73 68 72 69 67 68 74 7b 5c 75 72 6c 68 flushright{\urlh
00e0: 7b 68 74 74 70 3a 2f 2f 73 79 6e 74 68 63 6f 64 {http://synthcod
00f0: 65 2e 63 6f 6d 2f 73 63 68 65 6d 65 2f 66 6d 74 e.com/scheme/fmt
0100: 2f 66 6d 74 2d 30 2e 38 2e 34 2e 74 61 72 2e 67 /fmt-0.8.4.tar.g
0110: 7a 7d 7b 44 6f 77 6e 6c 6f 61 64 20 56 65 72 73 z}{Download Vers
0120: 69 6f 6e 20 30 2e 38 2e 34 7d 7d 0a 0a 5c 65 76 ion 0.8.4}}..\ev
0130: 61 6c 28 64 69 73 70 6c 61 79 20 22 3c 62 72 20 al(display "<br
0140: 2f 3e 3c 62 72 20 2f 3e 5c 6e 5c 6e 22 29 0a 0a /><br />\n\n")..
0150: 41 20 6c 69 62 72 61 72 79 20 6f 66 20 70 72 6f A library of pro
0160: 63 65 64 75 72 65 73 20 66 6f 72 20 66 6f 72 6d cedures for form
0170: 61 74 74 69 6e 67 20 53 63 68 65 6d 65 20 6f 62 atting Scheme ob
0180: 6a 65 63 74 73 20 74 6f 20 74 65 78 74 20 69 6e jects to text in
0190: 0a 76 61 72 69 6f 75 73 20 77 61 79 73 2c 20 61 .various ways, a
01a0: 6e 64 20 66 6f 72 20 65 61 73 69 6c 79 20 63 6f nd for easily co
01b0: 6e 63 61 74 65 6e 61 74 69 6e 67 2c 20 63 6f 6d ncatenating, com
01c0: 70 6f 73 69 6e 67 20 61 6e 64 20 65 78 74 65 6e posing and exten
01d0: 64 69 6e 67 0a 74 68 65 73 65 20 66 6f 72 6d 61 ding.these forma
01e0: 74 74 65 72 73 20 65 66 66 69 63 69 65 6e 74 6c tters efficientl
01f0: 79 20 77 69 74 68 6f 75 74 20 72 65 73 6f 72 74 y without resort
0200: 69 6e 67 20 74 6f 20 63 61 70 74 75 72 69 6e 67 ing to capturing
0210: 20 61 6e 64 0a 6d 61 6e 69 70 75 6c 61 74 69 6e and.manipulatin
0220: 67 20 69 6e 74 65 72 6d 65 64 69 61 74 65 20 73 g intermediate s
0230: 74 72 69 6e 67 73 2e 0a 0a 5c 65 76 61 6c 28 64 trings...\eval(d
0240: 69 73 70 6c 61 79 20 22 3c 62 72 20 2f 3e 3c 62 isplay "<br /><b
0250: 72 20 2f 3e 5c 6e 5c 6e 22 29 0a 0a 5c 73 65 63 r />\n\n")..\sec
0260: 74 69 6f 6e 7b 54 61 62 6c 65 20 6f 66 20 43 6f tion{Table of Co
0270: 6e 74 65 6e 74 73 7d 0a 0a 5c 65 76 61 6c 28 64 ntents}..\eval(d
0280: 69 73 70 6c 61 79 20 22 5c 6e 5c 6e 3c 21 2d 2d isplay "\n\n<!--
0290: 20 54 4f 43 20 2d 2d 3e 5c 6e 5c 6e 22 29 0a 0a TOC -->\n\n")..
02a0: 5c 65 76 61 6c 28 64 69 73 70 6c 61 79 20 22 3c \eval(display "<
02b0: 62 72 20 2f 3e 3c 62 72 20 2f 3e 5c 6e 5c 6e 22 br /><br />\n\n"
02c0: 29 0a 0a 5c 73 65 63 74 69 6f 6e 7b 49 6e 73 74 )..\section{Inst
02d0: 61 6c 6c 61 74 69 6f 6e 7d 0a 0a 41 76 61 69 6c allation}..Avail
02e0: 61 62 6c 65 20 66 6f 72 20 43 68 69 63 6b 65 6e able for Chicken
02f0: 20 61 73 20 74 68 65 20 5c 70 7b 66 6d 74 7d 20 as the \p{fmt}
0300: 65 67 67 2c 20 70 72 6f 76 69 64 69 6e 67 20 74 egg, providing t
0310: 68 65 20 5c 71 7b 66 6d 74 7d 2c 0a 5c 71 7b 66 he \q{fmt},.\q{f
0320: 6d 74 2d 63 7d 2c 20 5c 71 7b 66 6d 74 2d 63 6f mt-c}, \q{fmt-co
0330: 6c 6f 72 7d 20 61 6e 64 20 5c 71 7b 66 6d 74 2d lor} and \q{fmt-
0340: 75 6e 69 63 6f 64 65 7d 20 65 78 74 65 6e 73 69 unicode} extensi
0350: 6f 6e 73 2e 20 20 54 6f 20 69 6e 73 74 61 6c 6c ons. To install
0360: 0a 6d 61 6e 75 61 6c 6c 79 20 66 6f 72 20 43 68 .manually for Ch
0370: 69 63 6b 65 6e 20 6a 75 73 74 20 72 75 6e 20 5c icken just run \
0380: 70 7b 22 63 68 69 63 6b 65 6e 2d 73 65 74 75 70 p{"chicken-setup
0390: 22 7d 20 69 6e 20 74 68 65 20 66 6d 74 0a 64 69 "} in the fmt.di
03a0: 72 65 63 74 6f 72 79 2e 0a 0a 46 6f 72 20 47 61 rectory...For Ga
03b0: 75 63 68 65 20 72 75 6e 20 5c 70 7b 22 6d 61 6b uche run \p{"mak
03c0: 65 20 67 61 75 63 68 65 20 26 26 20 6d 61 6b 65 e gauche && make
03d0: 20 69 6e 73 74 61 6c 6c 2d 67 61 75 63 68 65 22 install-gauche"
03e0: 7d 2e 20 20 54 68 65 20 6d 6f 64 75 6c 65 73 0a }. The modules.
03f0: 61 72 65 20 69 6e 73 74 61 6c 6c 65 64 20 61 73 are installed as
0400: 20 5c 71 7b 74 65 78 74 2e 66 6d 74 7d 2c 20 5c \q{text.fmt}, \
0410: 71 7b 74 65 78 74 2e 66 6d 74 2e 63 7d 2c 20 5c q{text.fmt.c}, \
0420: 71 7b 74 65 78 74 2e 66 6d 74 2e 63 6f 6c 6f 72 q{text.fmt.color
0430: 7d 20 61 6e 64 0a 5c 71 7b 74 65 78 74 2e 66 6d } and.\q{text.fm
0440: 74 2e 75 6e 69 63 6f 64 65 7d 2e 0a 0a 46 6f 72 t.unicode}...For
0450: 20 4d 7a 53 63 68 65 6d 65 20 79 6f 75 20 63 61 MzScheme you ca
0460: 6e 20 64 6f 77 6e 6c 6f 61 64 20 61 6e 64 20 69 n download and i
0470: 6e 73 74 61 6c 6c 20 74 68 65 20 6c 61 74 65 73 nstall the lates
0480: 74 20 5c 70 7b 66 6d 74 2e 70 6c 74 7d 20 79 6f t \p{fmt.plt} yo
0490: 75 72 73 65 6c 66 0a 66 72 6f 6d 3a 0a 0a 20 20 urself.from:..
04a0: 5c 75 72 6c 68 7b 68 74 74 70 3a 2f 2f 73 79 6e \urlh{http://syn
04b0: 74 68 63 6f 64 65 2e 63 6f 6d 2f 73 63 68 65 6d thcode.com/schem
04c0: 65 2f 66 6d 74 2f 66 6d 74 2e 70 6c 74 7d 7b 68 e/fmt/fmt.plt}{h
04d0: 74 74 70 3a 2f 2f 73 79 6e 74 68 63 6f 64 65 2e ttp://synthcode.
04e0: 63 6f 6d 2f 73 63 68 65 6d 65 2f 66 6d 74 2f 66 com/scheme/fmt/f
04f0: 6d 74 2e 70 6c 74 7d 0a 0a 54 6f 20 62 75 69 6c mt.plt}..To buil
0500: 64 20 74 68 65 20 5c 70 7b 66 6d 74 2e 70 6c 74 d the \p{fmt.plt
0510: 7d 20 66 6f 72 20 79 6f 75 72 73 65 6c 66 20 79 } for yourself y
0520: 6f 75 20 63 61 6e 20 72 75 6e 20 5c 70 7b 22 6d ou can run \p{"m
0530: 61 6b 65 20 6d 7a 73 63 68 65 6d 65 22 7d 2e 0a ake mzscheme"}..
0540: 0a 46 6f 72 20 53 63 68 65 6d 65 34 38 20 74 68 .For Scheme48 th
0550: 65 20 70 61 63 6b 61 67 65 20 64 65 73 63 72 69 e package descri
0560: 70 74 69 6f 6e 73 20 61 72 65 20 69 6e 20 5c 70 ptions are in \p
0570: 7b 66 6d 74 2d 73 63 68 65 6d 65 34 38 2e 73 63 {fmt-scheme48.sc
0580: 6d 7d 3a 0a 0a 5c 71 7b 0a 3e 20 2c 63 6f 6e 66 m}:..\q{.> ,conf
0590: 69 67 20 2c 6c 6f 61 64 20 66 6d 74 2d 73 63 68 ig ,load fmt-sch
05a0: 65 6d 65 34 38 2e 73 63 6d 0a 3e 20 2c 6f 70 65 eme48.scm.> ,ope
05b0: 6e 20 66 6d 74 0a 7d 0a 0a 46 6f 72 20 6f 74 68 n fmt.}..For oth
05c0: 65 72 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f er implementatio
05d0: 6e 73 20 79 6f 75 27 6c 6c 20 6e 65 65 64 20 74 ns you'll need t
05e0: 6f 20 6c 6f 61 64 20 53 52 46 49 27 73 20 31 2c o load SRFI's 1,
05f0: 20 36 2c 20 31 33 2c 20 33 33 0a 28 73 61 6d 70 6, 13, 33.(samp
0600: 6c 65 20 70 72 6f 76 69 64 65 64 29 20 61 6e 64 le provided) and
0610: 20 36 39 20 28 61 6c 73 6f 20 70 72 6f 76 69 64 69 (also provid
0620: 65 64 29 2c 20 61 6e 64 20 74 68 65 6e 20 6c 6f ed), and then lo
0630: 61 64 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 ad the following
0640: 0a 66 69 6c 65 73 3a 0a 0a 5c 71 7b 0a 20 20 28 .files:..\q{. (
0650: 6c 6f 61 64 20 22 6c 65 74 2d 6f 70 74 69 6f 6e load "let-option
0660: 61 6c 73 2e 73 63 6d 22 29 20 20 3b 20 69 66 20 als.scm") ; if
0670: 79 6f 75 20 64 6f 6e 27 74 20 68 61 76 65 20 4c you don't have L
0680: 45 54 2d 4f 50 54 49 4f 4e 41 4c 53 2a 0a 20 20 ET-OPTIONALS*.
0690: 28 6c 6f 61 64 20 22 72 65 61 64 2d 6c 69 6e 65 (load "read-line
06a0: 2e 73 63 6d 22 29 20 20 20 20 20 20 3b 20 69 66 .scm") ; if
06b0: 20 79 6f 75 20 64 6f 6e 27 74 20 68 61 76 65 20 you don't have
06c0: 52 45 41 44 2d 4c 49 4e 45 0a 20 20 28 6c 6f 61 READ-LINE. (loa
06d0: 64 20 22 73 74 72 69 6e 67 2d 70 6f 72 74 73 2e d "string-ports.
06e0: 73 63 6d 22 29 20 20 20 3b 20 69 66 20 79 6f 75 scm") ; if you
06f0: 20 64 6f 6e 27 74 20 68 61 76 65 20 43 41 4c 4c don't have CALL
0700: 2d 57 49 54 48 2d 4f 55 54 50 55 54 2d 53 54 52 -WITH-OUTPUT-STR
0710: 49 4e 47 0a 20 20 28 6c 6f 61 64 20 22 6d 61 6b ING. (load "mak
0720: 65 2d 65 71 2d 74 61 62 6c 65 2e 73 63 6d 22 29 e-eq-table.scm")
0730: 0a 20 20 28 6c 6f 61 64 20 22 6d 61 6e 74 69 73 . (load "mantis
0740: 73 61 2e 73 63 6d 22 29 0a 20 20 28 6c 6f 61 64 sa.scm"). (load
0750: 20 22 66 6d 74 2e 73 63 6d 22 29 0a 20 20 28 6c "fmt.scm"). (l
0760: 6f 61 64 20 22 66 6d 74 2d 70 72 65 74 74 79 2e oad "fmt-pretty.
0770: 73 63 6d 22 29 20 20 20 20 20 3b 20 6f 70 74 69 scm") ; opti
0780: 6f 6e 61 6c 20 70 72 65 74 74 79 20 70 72 69 6e onal pretty prin
0790: 74 69 6e 67 0a 20 20 28 6c 6f 61 64 20 22 66 6d ting. (load "fm
07a0: 74 2d 63 6f 6c 75 6d 6e 2e 73 63 6d 22 29 20 20 t-column.scm")
07b0: 20 20 20 3b 20 6f 70 74 69 6f 6e 61 6c 20 63 6f ; optional co
07c0: 6c 75 6d 6e 61 72 20 6f 75 74 70 75 74 0a 20 20 lumnar output.
07d0: 28 6c 6f 61 64 20 22 66 6d 74 2d 63 2e 73 63 6d (load "fmt-c.scm
07e0: 22 29 20 20 20 20 20 20 20 20 20 20 3b 20 6f 70 ") ; op
07f0: 74 69 6f 6e 61 6c 20 43 20 66 6f 72 6d 61 74 74 tional C formatt
0800: 69 6e 67 20 75 74 69 6c 69 74 69 65 73 0a 20 20 ing utilities.
0810: 28 6c 6f 61 64 20 22 66 6d 74 2d 63 6f 6c 6f 72 (load "fmt-color
0820: 2e 73 63 6d 22 29 20 20 20 20 20 20 3b 20 6f 70 .scm") ; op
0830: 74 69 6f 6e 61 6c 20 63 6f 6c 6f 72 20 75 74 69 tional color uti
0840: 6c 69 74 69 65 73 0a 20 20 28 6c 6f 61 64 20 22 lities. (load "
0850: 66 6d 74 2d 75 6e 69 63 6f 64 65 2e 73 63 6d 22 fmt-unicode.scm"
0860: 29 20 20 20 20 3b 20 6f 70 74 69 6f 6e 61 6c 20 ) ; optional
0870: 55 6e 69 63 6f 64 65 2d 61 77 61 72 65 20 66 6f Unicode-aware fo
0880: 72 6d 61 74 74 69 6e 67 2c 0a 20 20 20 20 20 20 rmatting,.
0890: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
08a0: 20 20 20 20 20 20 20 20 3b 20 20 20 61 6c 73 6f ; also
08b0: 20 72 65 71 75 69 72 65 73 20 53 52 46 49 2d 34 requires SRFI-4
08c0: 20 6f 72 20 53 52 46 49 2d 36 36 0a 7d 0a 0a 5c or SRFI-66.}..\
08d0: 73 65 63 74 69 6f 6e 7b 42 61 63 6b 67 72 6f 75 section{Backgrou
08e0: 6e 64 7d 0a 0a 54 68 65 72 65 20 61 72 65 20 73 nd}..There are s
08f0: 65 76 65 72 61 6c 20 61 70 70 72 6f 61 63 68 65 everal approache
0900: 73 20 74 6f 20 74 65 78 74 20 66 6f 72 6d 61 74 s to text format
0910: 74 69 6e 67 2e 20 20 42 75 69 6c 64 69 6e 67 20 ting. Building
0920: 73 74 72 69 6e 67 73 20 74 6f 0a 5c 71 7b 64 69 strings to.\q{di
0930: 73 70 6c 61 79 7d 20 69 73 20 6e 6f 74 20 61 63 splay} is not ac
0940: 63 65 70 74 61 62 6c 65 2c 20 73 69 6e 63 65 20 ceptable, since
0950: 69 74 20 64 6f 65 73 6e 27 74 20 73 63 61 6c 65 it doesn't scale
0960: 20 74 6f 20 76 65 72 79 20 6c 61 72 67 65 0a 6f to very large.o
0970: 75 74 70 75 74 2e 20 20 54 68 65 20 73 69 6d 70 utput. The simp
0980: 6c 65 73 74 20 72 65 61 6c 69 73 74 69 63 20 69 lest realistic i
0990: 64 65 61 2c 20 61 6e 64 20 77 68 61 74 20 70 65 dea, and what pe
09a0: 6f 70 6c 65 20 72 65 73 6f 72 74 20 74 6f 20 69 ople resort to i
09b0: 6e 0a 74 79 70 69 63 61 6c 20 70 6f 72 74 61 62 n.typical portab
09c0: 6c 65 20 53 63 68 65 6d 65 2c 20 69 73 20 74 6f le Scheme, is to
09d0: 20 69 6e 74 65 72 6c 65 61 76 65 20 5c 71 7b 64 interleave \q{d
09e0: 69 73 70 6c 61 79 7d 20 61 6e 64 20 5c 71 7b 77 isplay} and \q{w
09f0: 72 69 74 65 7d 0a 61 6e 64 20 6d 61 6e 75 61 6c rite}.and manual
0a00: 20 6c 6f 6f 70 73 2c 20 62 75 74 20 74 68 69 73 loops, but this
0a10: 20 69 73 20 62 6f 74 68 20 65 78 74 72 65 6d 65 is both extreme
0a20: 6c 79 20 76 65 72 62 6f 73 65 20 61 6e 64 20 64 ly verbose and d
0a30: 6f 65 73 6e 27 74 0a 63 6f 6d 70 6f 73 65 20 77 oesn't.compose w
0a40: 65 6c 6c 2e 20 20 41 20 73 69 6d 70 6c 65 20 63 ell. A simple c
0a50: 6f 6e 63 65 70 74 20 73 75 63 68 20 61 73 20 70 oncept such as p
0a60: 61 64 64 69 6e 67 20 73 70 61 63 65 20 63 61 6e adding space can
0a70: 27 74 20 62 65 0a 61 63 68 69 65 76 65 64 20 64 't be.achieved d
0a80: 69 72 65 63 74 6c 79 20 77 69 74 68 6f 75 74 20 irectly without
0a90: 73 6f 6d 65 68 6f 77 20 63 61 70 74 75 72 69 6e somehow capturin
0aa0: 67 20 69 6e 74 65 72 6d 65 64 69 61 74 65 20 6f g intermediate o
0ab0: 75 74 70 75 74 2e 0a 0a 54 68 65 20 74 72 61 64 utput...The trad
0ac0: 69 74 69 6f 6e 61 6c 20 61 70 70 72 6f 61 63 68 itional approach
0ad0: 20 69 73 20 74 6f 20 75 73 65 20 74 65 6d 70 6c is to use templ
0ae0: 61 74 65 73 20 2d 20 74 79 70 69 63 61 6c 6c 79 ates - typically
0af0: 20 73 74 72 69 6e 67 73 2c 0a 74 68 6f 75 67 68 strings,.though
0b00: 20 69 6e 20 74 68 65 6f 72 79 20 61 6e 79 20 6f in theory any o
0b10: 62 6a 65 63 74 20 63 6f 75 6c 64 20 62 65 20 75 bject could be u
0b20: 73 65 64 20 61 6e 64 20 69 6e 64 65 65 64 20 45 sed and indeed E
0b30: 6d 61 63 73 27 20 6d 6f 64 65 2d 6c 69 6e 65 0a macs' mode-line.
0b40: 66 6f 72 6d 61 74 20 74 65 6d 70 6c 61 74 65 73 format templates
0b50: 20 61 6c 6c 6f 77 20 61 72 62 69 74 72 61 72 79 allow arbitrary
0b60: 20 73 65 78 70 73 2e 20 20 54 65 6d 70 6c 61 74 sexps. Templat
0b70: 65 73 20 63 61 6e 20 75 73 65 20 65 69 74 68 65 es can use eithe
0b80: 72 0a 65 73 63 61 70 65 20 73 65 71 75 65 6e 63 r.escape sequenc
0b90: 65 73 20 28 61 73 20 69 6e 20 43 27 73 20 5c 71 es (as in C's \q
0ba0: 7b 70 72 69 6e 74 66 7d 20 61 6e 64 20 5c 75 72 {printf} and \ur
0bb0: 6c 68 7b 23 42 49 42 49 54 45 4d 5f 32 7d 7b 43 lh{#BIBITEM_2}{C
0bc0: 4c 27 73 7d 0a 5c 71 7b 66 6f 72 6d 61 74 7d 29 L's}.\q{format})
0bd0: 20 6f 72 20 70 61 74 74 65 72 6e 20 6d 61 74 63 or pattern matc
0be0: 68 69 6e 67 20 28 61 73 20 69 6e 20 56 69 73 75 hing (as in Visu
0bf0: 61 6c 20 42 61 73 69 63 27 73 20 5c 71 7b 46 6f al Basic's \q{Fo
0c00: 72 6d 61 74 7d 2c 0a 5c 75 72 6c 68 7b 23 42 49 rmat},.\urlh{#BI
0c10: 42 49 54 45 4d 5f 36 7d 7b 50 65 72 6c 36 27 73 BITEM_6}{Perl6's
0c20: 7d 20 5c 71 7b 66 6f 72 6d 7d 2c 20 61 6e 64 20 } \q{form}, and
0c30: 53 51 4c 20 64 61 74 65 20 66 6f 72 6d 61 74 73 SQL date formats
0c40: 29 2e 20 20 54 68 65 0a 70 72 69 6d 61 72 79 20 ). The.primary
0c50: 64 69 73 61 64 76 61 6e 74 61 67 65 20 6f 66 20 disadvantage of
0c60: 74 65 6d 70 6c 61 74 65 73 20 69 73 20 74 68 65 templates is the
0c70: 20 72 65 6c 61 74 69 76 65 20 64 69 66 66 69 63 relative diffic
0c80: 75 6c 74 79 20 28 75 73 75 61 6c 6c 79 0a 69 6d ulty (usually.im
0c90: 70 6f 73 73 69 62 69 6c 69 74 79 29 20 6f 66 20 possibility) of
0ca0: 65 78 74 65 6e 64 69 6e 67 20 74 68 65 6d 2c 20 extending them,
0cb0: 74 68 65 69 72 20 6f 70 61 71 75 65 6e 65 73 73 their opaqueness
0cc0: 2c 20 61 6e 64 20 74 68 65 0a 75 6e 72 65 61 64 , and the.unread
0cd0: 61 62 69 6c 69 74 79 20 74 68 61 74 20 61 72 69 ability that ari
0ce0: 73 65 73 20 77 69 74 68 20 63 6f 6d 70 6c 65 78 ses with complex
0cf0: 20 66 6f 72 6d 61 74 73 2e 20 20 54 65 6d 70 6c formats. Templ
0d00: 61 74 65 73 20 61 72 65 20 6e 6f 74 0a 77 69 74 ates are not.wit
0d10: 68 6f 75 74 20 74 68 65 69 72 20 61 64 76 61 6e hout their advan
0d20: 74 61 67 65 73 2c 20 62 75 74 20 74 68 65 79 20 tages, but they
0d30: 61 72 65 20 61 6c 72 65 61 64 79 20 61 64 64 72 are already addr
0d40: 65 73 73 65 64 20 62 79 20 6f 74 68 65 72 0a 6c essed by other.l
0d50: 69 62 72 61 72 69 65 73 20 73 75 63 68 20 61 73 ibraries such as
0d60: 20 5c 75 72 6c 68 7b 23 42 49 42 49 54 45 4d 5f \urlh{#BIBITEM_
0d70: 33 7d 7b 53 52 46 49 2d 32 38 7d 20 61 6e 64 0a 3}{SRFI-28} and.
0d80: 5c 75 72 6c 68 7b 23 42 49 42 49 54 45 4d 5f 34 \urlh{#BIBITEM_4
0d90: 7d 7b 53 52 46 49 2d 34 38 7d 2e 0a 0a 54 68 69 }{SRFI-48}...Thi
0da0: 73 20 6c 69 62 72 61 72 79 20 74 61 6b 65 73 20 s library takes
0db0: 61 20 63 6f 6d 62 69 6e 61 74 6f 72 20 61 70 70 a combinator app
0dc0: 72 6f 61 63 68 2e 20 20 46 6f 72 6d 61 74 73 20 roach. Formats
0dd0: 61 72 65 20 6e 65 73 74 65 64 20 63 68 61 69 6e are nested chain
0de0: 73 0a 6f 66 20 63 6c 6f 73 75 72 65 73 2c 20 77 s.of closures, w
0df0: 68 69 63 68 20 61 72 65 20 63 61 6c 6c 65 64 20 hich are called
0e00: 74 6f 20 70 72 6f 64 75 63 65 20 74 68 65 69 72 to produce their
0e10: 20 6f 75 74 70 75 74 20 61 73 20 6e 65 65 64 65 output as neede
0e20: 64 2e 0a 54 68 65 20 70 72 69 6d 61 72 79 20 67 d..The primary g
0e30: 6f 61 6c 20 6f 66 20 74 68 69 73 20 6c 69 62 72 oal of this libr
0e40: 61 72 79 20 69 73 20 74 6f 20 68 61 76 65 2c 20 ary is to have,
0e50: 66 69 72 73 74 20 61 6e 64 20 66 6f 72 65 6d 6f first and foremo
0e60: 73 74 2c 20 61 0a 6d 61 78 69 6d 61 6c 6c 79 20 st, a.maximally
0e70: 65 78 70 72 65 73 73 69 76 65 20 61 6e 64 20 65 expressive and e
0e80: 78 74 65 6e 73 69 62 6c 65 20 66 6f 72 6d 61 74 xtensible format
0e90: 74 69 6e 67 20 6c 69 62 72 61 72 79 2e 20 20 54 ting library. T
0ea0: 68 65 20 6e 65 78 74 0a 6d 6f 73 74 20 69 6d 70 he next.most imp
0eb0: 6f 72 74 61 6e 74 20 67 6f 61 6c 20 69 73 20 73 ortant goal is s
0ec0: 63 61 6c 61 62 69 6c 69 74 79 20 2d 20 74 6f 20 calability - to
0ed0: 62 65 20 61 62 6c 65 20 74 6f 20 68 61 6e 64 6c be able to handl
0ee0: 65 0a 61 72 62 69 74 72 61 72 69 6c 79 20 6c 61 e.arbitrarily la
0ef0: 72 67 65 20 6f 75 74 70 75 74 20 61 6e 64 20 6e rge output and n
0f00: 6f 74 20 62 75 69 6c 64 20 69 6e 74 65 72 6d 65 ot build interme
0f10: 64 69 61 74 65 20 72 65 73 75 6c 74 73 20 65 78 diate results ex
0f20: 63 65 70 74 0a 77 68 65 72 65 20 6e 65 63 65 73 cept.where neces
0f30: 73 61 72 79 2e 20 20 54 68 65 20 74 68 69 72 64 sary. The third
0f40: 20 67 6f 61 6c 20 69 73 20 62 72 65 76 69 74 79 goal is brevity
0f50: 20 61 6e 64 20 65 61 73 65 20 6f 66 20 75 73 65 and ease of use
0f60: 2e 0a 0a 5c 73 65 63 74 69 6f 6e 7b 55 73 61 67 ...\section{Usag
0f70: 65 7d 0a 0a 54 68 65 20 70 72 69 6d 61 72 79 20 e}..The primary
0f80: 69 6e 74 65 72 66 61 63 65 20 69 73 20 74 68 65 interface is the
0f90: 20 5c 71 7b 66 6d 74 7d 20 70 72 6f 63 65 64 75 \q{fmt} procedu
0fa0: 72 65 3a 0a 0a 20 20 5c 71 7b 28 66 6d 74 20 3c re:.. \q{(fmt <
0fb0: 6f 75 74 70 75 74 2d 64 65 73 74 3e 20 3c 66 6f output-dest> <fo
0fc0: 72 6d 61 74 3e 20 2e 2e 2e 29 7d 0a 0a 77 68 65 rmat> ...)}..whe
0fd0: 72 65 20 5c 71 7b 3c 6f 75 74 70 75 74 2d 64 65 re \q{<output-de
0fe0: 73 74 3e 7d 20 68 61 73 20 74 68 65 20 73 61 6d st>} has the sam
0ff0: 65 20 73 65 6d 61 6e 74 69 63 73 20 61 73 20 77 e semantics as w
1000: 69 74 68 20 5c 71 7b 66 6f 72 6d 61 74 7d 20 2d ith \q{format} -
1010: 0a 73 70 65 63 69 66 69 63 61 6c 6c 79 20 69 74 .specifically it
1020: 20 63 61 6e 20 62 65 20 61 6e 20 6f 75 74 70 75 can be an outpu
1030: 74 2d 70 6f 72 74 2c 20 5c 71 7b 23 74 7d 20 74 t-port, \q{#t} t
1040: 6f 20 69 6e 64 69 63 61 74 65 20 74 68 65 20 63 o indicate the c
1050: 75 72 72 65 6e 74 0a 6f 75 74 70 75 74 20 70 6f urrent.output po
1060: 72 74 2c 20 6f 72 20 5c 71 7b 23 66 7d 20 74 6f rt, or \q{#f} to
1070: 20 61 63 63 75 6d 75 6c 61 74 65 20 6f 75 74 70 accumulate outp
1080: 75 74 20 69 6e 74 6f 20 61 20 73 74 72 69 6e 67 ut into a string
1090: 2e 0a 0a 45 61 63 68 20 5c 71 7b 3c 66 6f 72 6d ...Each \q{<form
10a0: 61 74 3e 7d 20 73 68 6f 75 6c 64 20 62 65 20 61 at>} should be a
10b0: 20 66 6f 72 6d 61 74 20 63 6c 6f 73 75 72 65 20 format closure
10c0: 61 73 20 64 69 73 63 75 73 73 65 64 20 62 65 6c as discussed bel
10d0: 6f 77 2e 20 20 41 73 20 61 0a 63 6f 6e 76 65 6e ow. As a.conven
10e0: 69 65 6e 63 65 2c 20 6e 6f 6e 2d 70 72 6f 63 65 ience, non-proce
10f0: 64 75 72 65 20 61 72 67 75 6d 65 6e 74 73 20 61 dure arguments a
1100: 72 65 20 61 6c 73 6f 20 61 6c 6c 6f 77 65 64 20 re also allowed
1110: 61 6e 64 20 61 72 65 0a 66 6f 72 6d 61 74 74 65 and are.formatte
1120: 64 20 73 69 6d 69 6c 61 72 20 74 6f 20 5c 71 7b d similar to \q{
1130: 64 69 73 70 6c 61 79 7d 2c 20 73 6f 20 74 68 61 display}, so tha
1140: 74 0a 0a 20 20 5c 71 7b 28 66 6d 74 20 23 66 20 t.. \q{(fmt #f
1150: 22 52 65 73 75 6c 74 3a 20 22 20 72 65 73 20 6e "Result: " res n
1160: 6c 29 7d 0a 0a 77 6f 75 6c 64 20 72 65 74 75 72 l)}..would retur
1170: 6e 20 74 68 65 20 73 74 72 69 6e 67 20 5c 71 7b n the string \q{
1180: 22 52 65 73 75 6c 74 3a 20 34 32 5c 6e 22 7d 2c "Result: 42\n"},
1190: 20 61 73 73 75 6d 69 6e 67 20 5c 71 7b 52 45 53 assuming \q{RES
11a0: 7d 20 69 73 20 62 6f 75 6e 64 0a 74 6f 20 5c 71 } is bound.to \q
11b0: 7b 34 32 7d 2e 0a 0a 5c 71 7b 6e 6c 7d 20 69 73 {42}...\q{nl} is
11c0: 20 74 68 65 20 6e 65 77 6c 69 6e 65 20 66 6f 72 the newline for
11d0: 6d 61 74 20 63 6f 6d 62 69 6e 61 74 6f 72 2e 0a mat combinator..
11e0: 0a 5c 73 65 63 74 69 6f 6e 7b 53 70 65 63 69 66 .\section{Specif
11f0: 69 63 61 74 69 6f 6e 7d 0a 0a 54 68 65 20 70 72 ication}..The pr
1200: 6f 63 65 64 75 72 65 20 6e 61 6d 65 73 20 68 61 ocedure names ha
1210: 76 65 20 67 6f 6e 65 20 74 68 72 6f 75 67 68 20 ve gone through
1220: 73 65 76 65 72 61 6c 20 76 61 72 69 61 74 69 6f several variatio
1230: 6e 73 2c 20 61 6e 64 20 49 27 6d 0a 73 74 69 6c ns, and I'm.stil
1240: 6c 20 6f 70 65 6e 20 74 6f 20 6e 65 77 20 73 75 l open to new su
1250: 67 67 65 73 74 69 6f 6e 73 2e 20 20 54 68 65 20 ggestions. The
1260: 63 75 72 72 65 6e 74 20 61 70 70 72 6f 61 63 68 current approach
1270: 20 69 73 20 74 6f 20 75 73 65 0a 61 62 62 72 65 is to use.abbre
1280: 76 69 61 74 65 64 20 66 6f 72 6d 73 20 6f 66 20 viated forms of
1290: 73 74 61 6e 64 61 72 64 20 6f 75 74 70 75 74 20 standard output
12a0: 70 72 6f 63 65 64 75 72 65 73 20 77 68 65 6e 20 procedures when
12b0: 64 65 66 69 6e 69 6e 67 20 61 6e 0a 65 71 75 69 defining an.equi
12c0: 76 61 6c 65 6e 74 20 66 6f 72 6d 61 74 20 63 6f valent format co
12d0: 6d 62 69 6e 61 74 6f 72 20 28 74 68 75 73 20 5c mbinator (thus \
12e0: 71 7b 64 69 73 70 6c 61 79 7d 20 62 65 63 6f 6d q{display} becom
12f0: 65 73 20 5c 71 7b 64 73 70 7d 20 61 6e 64 0a 5c es \q{dsp} and.\
1300: 71 7b 77 72 69 74 65 7d 20 62 65 63 6f 6d 65 73 q{write} becomes
1310: 20 5c 71 7b 77 72 74 7d 29 2c 20 61 6e 64 20 74 \q{wrt}), and t
1320: 6f 20 75 73 65 20 61 6e 20 5c 71 7b 66 6d 74 2d o use an \q{fmt-
1330: 7d 20 70 72 65 66 69 78 20 66 6f 72 0a 75 74 69 } prefix for.uti
1340: 6c 69 74 69 65 73 20 61 6e 64 20 6c 65 73 73 20 lities and less
1350: 63 6f 6d 6d 6f 6e 20 63 6f 6d 62 69 6e 61 74 6f common combinato
1360: 72 73 2e 20 20 56 61 72 69 61 6e 74 73 20 6f 66 rs. Variants of
1370: 20 74 68 65 20 73 61 6d 65 20 66 6f 72 6d 61 74 the same format
1380: 74 65 72 0a 67 65 74 20 61 20 5c 71 7b 2f 3c 76 ter.get a \q{/<v
1390: 61 72 69 61 6e 74 3e 7d 20 73 75 66 66 69 78 2e ariant>} suffix.
13a0: 0a 0a 5c 73 75 62 73 65 63 74 69 6f 6e 7b 46 6f ..\subsection{Fo
13b0: 72 6d 61 74 74 69 6e 67 20 4f 62 6a 65 63 74 73 rmatting Objects
13c0: 7d 0a 0a 5c 73 75 62 73 75 62 73 65 63 74 69 6f }..\subsubsectio
13d0: 6e 2a 7b 28 64 73 70 20 3c 6f 62 6a 3e 29 7d 0a n*{(dsp <obj>)}.
13e0: 0a 4f 75 74 70 75 74 73 20 5c 71 7b 3c 6f 62 6a .Outputs \q{<obj
13f0: 3e 7d 20 75 73 69 6e 67 20 5c 71 7b 64 69 73 70 >} using \q{disp
1400: 6c 61 79 7d 20 73 65 6d 61 6e 74 69 63 73 2e 20 lay} semantics.
1410: 20 53 70 65 63 69 66 69 63 61 6c 6c 79 2c 20 73 Specifically, s
1420: 74 72 69 6e 67 73 0a 61 72 65 20 6f 75 74 70 75 trings.are outpu
1430: 74 20 77 69 74 68 6f 75 74 20 73 75 72 72 6f 75 t without surrou
1440: 6e 64 69 6e 67 20 71 75 6f 74 65 73 20 6f 72 20 nding quotes or
1450: 65 73 63 61 70 69 6e 67 20 61 6e 64 20 63 68 61 escaping and cha
1460: 72 61 63 74 65 72 73 20 61 72 65 0a 77 72 69 74 racters are.writ
1470: 74 65 6e 20 61 73 20 69 66 20 62 79 20 5c 71 7b ten as if by \q{
1480: 77 72 69 74 65 2d 63 68 61 72 7d 2e 20 20 4f 74 write-char}. Ot
1490: 68 65 72 20 6f 62 6a 65 63 74 73 20 61 72 65 20 her objects are
14a0: 77 72 69 74 74 65 6e 20 61 73 20 77 69 74 68 0a written as with.
14b0: 5c 71 7b 77 72 69 74 65 7d 20 28 69 6e 63 6c 75 \q{write} (inclu
14c0: 64 69 6e 67 20 6e 65 73 74 65 64 20 73 74 72 69 ding nested stri
14d0: 6e 67 73 20 61 6e 64 20 63 68 61 72 73 20 69 6e ngs and chars in
14e0: 73 69 64 65 20 5c 71 7b 3c 6f 62 6a 3e 7d 29 2e side \q{<obj>}).
14f0: 20 20 54 68 69 73 0a 69 73 20 74 68 65 20 64 65 This.is the de
1500: 66 61 75 6c 74 20 62 65 68 61 76 69 6f 72 20 66 fault behavior f
1510: 6f 72 20 74 6f 70 2d 6c 65 76 65 6c 20 66 6f 72 or top-level for
1520: 6d 61 74 73 20 69 6e 20 5c 71 7b 66 6d 74 7d 2c mats in \q{fmt},
1530: 20 5c 71 7b 63 61 74 7d 20 61 6e 64 0a 6d 6f 73 \q{cat} and.mos
1540: 74 20 6f 74 68 65 72 20 68 69 67 68 65 72 2d 6f t other higher-o
1550: 72 64 65 72 20 63 6f 6d 62 69 6e 61 74 6f 72 73 rder combinators
1560: 2e 0a 0a 5c 73 75 62 73 75 62 73 65 63 74 69 6f ...\subsubsectio
1570: 6e 2a 7b 28 77 72 74 20 3c 6f 62 6a 3e 29 7d 0a n*{(wrt <obj>)}.
1580: 0a 4f 75 74 70 75 74 73 20 5c 71 7b 3c 6f 62 6a .Outputs \q{<obj
1590: 3e 7d 20 75 73 69 6e 67 20 5c 71 7b 77 72 69 74 >} using \q{writ
15a0: 65 7d 20 73 65 6d 61 6e 74 69 63 73 2e 20 20 48 e} semantics. H
15b0: 61 6e 64 6c 65 73 20 73 68 61 72 65 64 0a 73 74 andles shared.st
15c0: 72 75 63 74 75 72 65 73 20 61 73 20 69 6e 20 5c ructures as in \
15d0: 75 72 6c 68 7b 23 42 49 42 49 54 45 4d 5f 35 7d urlh{#BIBITEM_5}
15e0: 7b 53 52 46 49 2d 33 38 7d 2e 0a 0a 5c 73 75 62 {SRFI-38}...\sub
15f0: 73 75 62 73 65 63 74 69 6f 6e 2a 7b 28 77 72 74 subsection*{(wrt
1600: 2f 75 6e 73 68 61 72 65 64 20 3c 6f 62 6a 3e 29 /unshared <obj>)
1610: 7d 0a 0a 41 73 20 61 62 6f 76 65 2c 20 62 75 74 }..As above, but
1620: 20 64 6f 65 73 6e 27 74 20 68 61 6e 64 6c 65 20 doesn't handle
1630: 73 68 61 72 65 64 20 73 74 72 75 63 74 75 72 65 shared structure
1640: 73 2e 20 20 49 6e 66 69 6e 69 74 65 20 6c 6f 6f s. Infinite loo
1650: 70 73 20 63 61 6e 0a 73 74 69 6c 6c 20 62 65 20 ps can.still be
1660: 61 76 6f 69 64 65 64 20 69 66 20 75 73 65 64 20 avoided if used
1670: 69 6e 73 69 64 65 20 61 20 63 6f 6d 62 69 6e 61 inside a combina
1680: 74 6f 72 20 74 68 61 74 20 74 72 75 6e 63 61 74 tor that truncat
1690: 65 73 20 64 61 74 61 20 28 73 65 65 0a 5c 71 7b es data (see.\q{
16a0: 74 72 69 6d 7d 20 61 6e 64 20 5c 71 7b 66 69 74 trim} and \q{fit
16b0: 7d 20 62 65 6c 6f 77 29 2e 0a 0a 5c 73 75 62 73 } below)...\subs
16c0: 75 62 73 65 63 74 69 6f 6e 2a 7b 28 70 72 65 74 ubsection*{(pret
16d0: 74 79 20 3c 6f 62 6a 3e 29 7d 0a 0a 50 72 65 74 ty <obj>)}..Pret
16e0: 74 79 2d 70 72 69 6e 74 73 20 5c 71 7b 3c 6f 62 ty-prints \q{<ob
16f0: 6a 3e 7d 2e 20 20 41 6c 73 6f 20 68 61 6e 64 6c j>}. Also handl
1700: 65 73 20 73 68 61 72 65 64 20 73 74 72 75 63 74 es shared struct
1710: 75 72 65 73 2e 20 20 55 6e 6c 69 6b 65 20 6d 61 ures. Unlike ma
1720: 6e 79 0a 6f 74 68 65 72 20 70 72 65 74 74 79 20 ny.other pretty
1730: 70 72 69 6e 74 65 72 73 2c 20 76 65 63 74 6f 72 printers, vector
1740: 73 20 61 6e 64 20 64 61 74 61 20 6c 69 73 74 73 s and data lists
1750: 20 28 6c 69 73 74 73 20 74 68 61 74 20 64 6f 6e (lists that don
1760: 27 74 20 62 65 67 69 6e 0a 77 69 74 68 20 61 20 't begin.with a
1770: 28 6e 65 73 74 65 64 29 20 73 79 6d 62 6f 6c 29 (nested) symbol)
1780: 2c 20 61 72 65 20 70 72 69 6e 74 65 64 20 69 6e , are printed in
1790: 20 74 61 62 75 6c 61 72 20 66 6f 72 6d 61 74 20 tabular format
17a0: 77 68 65 6e 20 74 68 65 72 65 27 73 0a 72 6f 6f when there's.roo
17b0: 6d 2c 20 67 72 65 61 74 6c 79 20 73 61 76 69 6e m, greatly savin
17c0: 67 20 76 65 72 74 69 63 61 6c 20 73 70 61 63 65 g vertical space
17d0: 2e 0a 0a 5c 73 75 62 73 75 62 73 65 63 74 69 6f ...\subsubsectio
17e0: 6e 2a 7b 28 70 72 65 74 74 79 2f 75 6e 73 68 61 n*{(pretty/unsha
17f0: 72 65 64 20 3c 6f 62 6a 3e 29 7d 0a 0a 41 73 20 red <obj>)}..As
1800: 61 62 6f 76 65 20 62 75 74 20 77 69 74 68 6f 75 above but withou
1810: 74 20 73 68 61 72 69 6e 67 2e 0a 0a 5c 73 75 62 t sharing...\sub
1820: 73 75 62 73 65 63 74 69 6f 6e 2a 7b 28 73 6c 61 subsection*{(sla
1830: 73 68 69 66 69 65 64 20 3c 73 74 72 3e 20 5b 3c shified <str> [<
1840: 71 75 6f 74 65 2d 63 68 3e 20 3c 65 73 63 2d 63 quote-ch> <esc-c
1850: 68 3e 20 3c 72 65 6e 61 6d 65 72 3e 5d 29 7d 0a h> <renamer>])}.
1860: 0a 4f 75 74 70 75 74 73 20 74 68 65 20 73 74 72 .Outputs the str
1870: 69 6e 67 20 5c 71 7b 3c 73 74 72 3e 7d 2c 20 65 ing \q{<str>}, e
1880: 73 63 61 70 69 6e 67 20 61 6e 79 20 71 75 6f 74 scaping any quot
1890: 65 20 6f 72 20 65 73 63 61 70 65 20 63 68 61 72 e or escape char
18a0: 61 63 74 65 72 73 2e 0a 49 66 20 5c 71 7b 3c 65 acters..If \q{<e
18b0: 73 63 2d 63 68 3e 7d 20 69 73 20 5c 71 7b 23 66 sc-ch>} is \q{#f
18c0: 7d 20 65 73 63 61 70 65 73 20 6f 6e 6c 79 20 74 } escapes only t
18d0: 68 65 20 5c 71 7b 3c 71 75 6f 74 65 2d 63 68 3e he \q{<quote-ch>
18e0: 7d 20 62 79 0a 64 6f 75 62 6c 69 6e 67 20 69 74 } by.doubling it
18f0: 2c 20 61 73 20 69 6e 20 53 51 4c 20 73 74 72 69 , as in SQL stri
1900: 6e 67 73 20 61 6e 64 20 43 53 56 20 76 61 6c 75 ngs and CSV valu
1910: 65 73 2e 20 20 49 66 20 5c 71 7b 3c 72 65 6e 61 es. If \q{<rena
1920: 6d 65 72 3e 7d 20 69 73 0a 70 72 6f 76 69 64 65 mer>} is.provide
1930: 64 2c 20 69 74 20 73 68 6f 75 6c 64 20 62 65 20 d, it should be
1940: 61 20 70 72 6f 63 65 64 75 72 65 20 6f 66 20 6f a procedure of o
1950: 6e 65 20 63 68 61 72 61 63 74 65 72 20 77 68 69 ne character whi
1960: 63 68 20 6d 61 70 73 20 74 68 61 74 0a 63 68 61 ch maps that.cha
1970: 72 61 63 74 65 72 20 74 6f 20 69 74 73 20 65 73 racter to its es
1980: 63 61 70 65 20 76 61 6c 75 65 2c 20 65 2e 67 2e cape value, e.g.
1990: 20 5c 71 7b 23 5c 6e 65 77 6c 69 6e 65 20 3d 3e \q{#\newline =>
19a0: 20 23 5c 6e 7d 2c 20 6f 72 20 5c 71 7b 23 66 7d #\n}, or \q{#f}
19b0: 20 69 66 0a 74 68 65 72 65 20 69 73 20 6e 6f 20 if.there is no
19c0: 65 73 63 61 70 65 20 76 61 6c 75 65 2e 0a 0a 20 escape value...
19d0: 20 5c 71 7b 28 66 6d 74 20 23 66 20 28 73 6c 61 \q{(fmt #f (sla
19e0: 73 68 69 66 69 65 64 20 22 68 69 2c 20 5c 22 62 shified "hi, \"b
19f0: 6f 62 21 5c 22 22 29 29 7d 0a 0a 20 20 5c 71 7b ob!\""))}.. \q{
1a00: 3d 3e 20 22 68 69 2c 20 5c 22 62 6f 62 21 5c 22 => "hi, \"bob!\"
1a10: 22 7d 0a 0a 5c 73 75 62 73 75 62 73 65 63 74 69 "}..\subsubsecti
1a20: 6f 6e 2a 7b 28 6d 61 79 62 65 2d 73 6c 61 73 68 on*{(maybe-slash
1a30: 69 66 69 65 64 20 3c 73 74 72 3e 20 3c 70 72 65 ified <str> <pre
1a40: 64 3e 20 5b 3c 71 75 6f 74 65 2d 63 68 3e 20 3c d> [<quote-ch> <
1a50: 65 73 63 2d 63 68 3e 20 3c 72 65 6e 61 6d 65 72 esc-ch> <renamer
1a60: 3e 5d 29 7d 0a 0a 4c 69 6b 65 20 5c 71 7b 73 6c >])}..Like \q{sl
1a70: 61 73 68 69 66 69 65 64 7d 2c 20 62 75 74 20 66 ashified}, but f
1a80: 69 72 73 74 20 63 68 65 63 6b 73 20 69 66 20 61 irst checks if a
1a90: 6e 79 20 71 75 6f 74 69 6e 67 20 69 73 20 72 65 ny quoting is re
1aa0: 71 75 69 72 65 64 20 28 62 79 0a 74 68 65 20 65 quired (by.the e
1ab0: 78 69 73 74 65 6e 63 65 20 6f 66 20 65 69 74 68 xistence of eith
1ac0: 65 72 20 61 6e 79 20 71 75 6f 74 65 20 6f 72 20 er any quote or
1ad0: 65 73 63 61 70 65 20 63 68 61 72 61 63 74 65 72 escape character
1ae0: 73 2c 20 6f 72 20 61 6e 79 0a 63 68 61 72 61 63 s, or any.charac
1af0: 74 65 72 20 6d 61 74 63 68 69 6e 67 20 5c 71 7b ter matching \q{
1b00: 3c 70 72 65 64 3e 7d 29 2c 20 61 6e 64 20 69 66 <pred>}), and if
1b10: 20 73 6f 20 6f 75 74 70 75 74 73 20 74 68 65 20 so outputs the
1b20: 73 74 72 69 6e 67 20 69 6e 20 71 75 6f 74 65 73 string in quotes
1b30: 0a 61 6e 64 20 77 69 74 68 20 65 73 63 61 70 65 .and with escape
1b40: 73 2e 20 20 4f 74 68 65 72 77 69 73 65 20 6f 75 s. Otherwise ou
1b50: 74 70 75 74 73 20 74 68 65 20 73 74 72 69 6e 67 tputs the string
1b60: 20 61 73 20 69 73 2e 0a 0a 20 20 5c 71 7b 28 66 as is... \q{(f
1b70: 6d 74 20 23 66 20 28 6d 61 79 62 65 2d 73 6c 61 mt #f (maybe-sla
1b80: 73 68 69 66 69 65 64 20 22 66 6f 6f 22 20 63 68 shified "foo" ch
1b90: 61 72 2d 77 68 69 74 65 73 70 61 63 65 3f 20 23 ar-whitespace? #
1ba0: 5c 22 29 29 7d 0a 0a 20 20 5c 71 7b 3d 3e 20 22 \"))}.. \q{=> "
1bb0: 66 6f 6f 22 7d 0a 0a 20 20 5c 71 7b 28 66 6d 74 foo"}.. \q{(fmt
1bc0: 20 23 66 20 28 6d 61 79 62 65 2d 73 6c 61 73 68 #f (maybe-slash
1bd0: 69 66 69 65 64 20 22 66 6f 6f 20 62 61 72 22 20 ified "foo bar"
1be0: 63 68 61 72 2d 77 68 69 74 65 73 70 61 63 65 3f char-whitespace?
1bf0: 20 23 5c 22 29 29 7d 0a 0a 20 20 5c 71 7b 3d 3e #\"))}.. \q{=>
1c00: 20 22 5c 22 66 6f 6f 20 62 61 72 5c 22 22 7d 0a "\"foo bar\""}.
1c10: 0a 20 20 5c 71 7b 28 66 6d 74 20 23 66 20 28 6d . \q{(fmt #f (m
1c20: 61 79 62 65 2d 73 6c 61 73 68 69 66 69 65 64 20 aybe-slashified
1c30: 22 66 6f 6f 5c 22 62 61 72 5c 22 62 61 7a 22 20 "foo\"bar\"baz"
1c40: 63 68 61 72 2d 77 68 69 74 65 73 70 61 63 65 3f char-whitespace?
1c50: 20 23 5c 22 29 29 7d 0a 0a 20 20 5c 71 7b 3d 3e #\"))}.. \q{=>
1c60: 20 22 5c 22 66 6f 6f 5c 22 62 61 72 5c 22 62 61 "\"foo\"bar\"ba
1c70: 7a 5c 22 22 7d 0a 0a 5c 73 75 62 73 65 63 74 69 z\""}..\subsecti
1c80: 6f 6e 7b 46 6f 72 6d 61 74 74 69 6e 67 20 4e 75 on{Formatting Nu
1c90: 6d 62 65 72 73 7d 0a 0a 5c 73 75 62 73 75 62 73 mbers}..\subsubs
1ca0: 65 63 74 69 6f 6e 2a 7b 28 6e 75 6d 20 3c 6e 3e ection*{(num <n>
1cb0: 20 5b 3c 72 61 64 69 78 3e 20 3c 70 72 65 63 69 [<radix> <preci
1cc0: 73 69 6f 6e 3e 20 3c 73 69 67 6e 3e 20 3c 63 6f sion> <sign> <co
1cd0: 6d 6d 61 3e 20 3c 63 6f 6d 6d 61 2d 73 65 70 3e mma> <comma-sep>
1ce0: 20 3c 64 65 63 69 6d 61 6c 2d 73 65 70 3e 5d 29 <decimal-sep>])
1cf0: 7d 0a 0a 46 6f 72 6d 61 74 73 20 61 20 73 69 6e }..Formats a sin
1d00: 67 6c 65 20 6e 75 6d 62 65 72 20 5c 71 7b 3c 6e gle number \q{<n
1d10: 3e 7d 2e 20 20 59 6f 75 20 63 61 6e 20 6f 70 74 >}. You can opt
1d20: 69 6f 6e 61 6c 6c 79 20 73 70 65 63 69 66 79 20 ionally specify
1d30: 61 6e 79 0a 5c 71 7b 3c 72 61 64 69 78 3e 7d 20 any.\q{<radix>}
1d40: 66 72 6f 6d 20 32 20 74 6f 20 33 36 20 28 65 76 from 2 to 36 (ev
1d50: 65 6e 20 69 66 20 5c 71 7b 3c 6e 3e 7d 20 69 73 en if \q{<n>} is
1d60: 6e 27 74 20 61 6e 20 69 6e 74 65 67 65 72 29 2e n't an integer).
1d70: 0a 5c 71 7b 3c 70 72 65 63 69 73 69 6f 6e 3e 7d .\q{<precision>}
1d80: 20 66 6f 72 63 65 73 20 61 20 66 69 78 65 64 2d forces a fixed-
1d90: 70 6f 69 6e 74 20 66 6f 72 6d 61 74 2e 0a 0a 41 point format...A
1da0: 20 5c 71 7b 3c 73 69 67 6e 3e 7d 20 6f 66 20 5c \q{<sign>} of \
1db0: 71 7b 23 74 7d 20 69 6e 64 69 63 61 74 65 73 20 q{#t} indicates
1dc0: 74 6f 20 6f 75 74 70 75 74 20 61 20 70 6c 75 73 to output a plus
1dd0: 20 73 69 67 6e 20 28 2b 29 20 66 6f 72 20 70 6f sign (+) for po
1de0: 73 69 74 69 76 65 0a 69 6e 74 65 67 65 72 73 2e sitive.integers.
1df0: 20 20 48 6f 77 65 76 65 72 2c 20 69 66 20 5c 71 However, if \q
1e00: 7b 3c 73 69 67 6e 3e 7d 20 69 73 20 61 20 63 68 {<sign>} is a ch
1e10: 61 72 61 63 74 65 72 2c 20 69 74 20 6d 65 61 6e aracter, it mean
1e20: 73 20 74 6f 20 77 72 61 70 20 74 68 65 0a 6e 75 s to wrap the.nu
1e30: 6d 62 65 72 20 77 69 74 68 20 74 68 61 74 20 63 mber with that c
1e40: 68 61 72 61 63 74 65 72 20 61 6e 64 20 69 74 73 haracter and its
1e50: 20 6d 69 72 72 6f 72 20 6f 70 70 6f 73 69 74 65 mirror opposite
1e60: 20 69 66 20 74 68 65 20 6e 75 6d 62 65 72 20 69 if the number i
1e70: 73 0a 6e 65 67 61 74 69 76 65 2e 20 20 46 6f 72 s.negative. For
1e80: 20 65 78 61 6d 70 6c 65 2c 20 5c 71 7b 23 5c 28 example, \q{#\(
1e90: 7d 20 70 72 69 6e 74 73 20 6e 65 67 61 74 69 76 } prints negativ
1ea0: 65 20 6e 75 6d 62 65 72 73 20 69 6e 20 70 61 72 e numbers in par
1eb0: 65 6e 74 68 65 73 69 73 2c 0a 66 69 6e 61 6e 63 enthesis,.financ
1ec0: 69 61 6c 20 73 74 79 6c 65 3a 20 5c 71 7b 2d 33 ial style: \q{-3
1ed0: 2e 31 34 20 3d 3e 20 28 33 2e 31 34 29 7d 0a 0a .14 => (3.14)}..
1ee0: 5c 71 7b 3c 63 6f 6d 6d 61 3e 7d 20 69 73 20 61 \q{<comma>} is a
1ef0: 6e 20 69 6e 74 65 67 65 72 20 73 70 65 63 69 66 n integer specif
1f00: 79 69 6e 67 20 74 68 65 20 6e 75 6d 62 65 72 20 ying the number
1f10: 6f 66 20 64 69 67 69 74 73 20 62 65 74 77 65 65 of digits betwee
1f20: 6e 0a 63 6f 6d 6d 61 73 2e 20 20 56 61 72 69 61 n.commas. Varia
1f30: 62 6c 65 20 6c 65 6e 67 74 68 2c 20 61 73 20 69 ble length, as i
1f40: 6e 20 73 75 62 63 6f 6e 74 69 6e 65 6e 74 61 6c n subcontinental
1f50: 2d 73 74 79 6c 65 2c 20 69 73 20 6e 6f 74 20 79 -style, is not y
1f60: 65 74 0a 73 75 70 70 6f 72 74 65 64 2e 0a 0a 5c et.supported...\
1f70: 71 7b 3c 63 6f 6d 6d 61 2d 73 65 70 3e 7d 20 69 q{<comma-sep>} i
1f80: 73 20 74 68 65 20 63 68 61 72 61 63 74 65 72 20 s the character
1f90: 74 6f 20 75 73 65 20 66 6f 72 20 63 6f 6d 6d 61 to use for comma
1fa0: 73 2c 20 64 65 66 61 75 6c 74 69 6e 67 20 74 6f s, defaulting to
1fb0: 20 5c 71 7b 23 5c 2c 7d 2e 0a 0a 5c 71 7b 3c 64 \q{#\,}...\q{<d
1fc0: 65 63 69 6d 61 6c 2d 73 65 70 3e 7d 20 69 73 20 ecimal-sep>} is
1fd0: 74 68 65 20 63 68 61 72 61 63 74 65 72 20 74 6f the character to
1fe0: 20 75 73 65 20 66 6f 72 20 64 65 63 69 6d 61 6c use for decimal
1ff0: 73 2c 20 64 65 66 61 75 6c 74 69 6e 67 20 74 6f s, defaulting to
2000: 0a 5c 71 7b 23 5c 2e 7d 2c 20 6f 72 20 74 6f 20 .\q{#\.}, or to
2010: 5c 71 7b 23 5c 2c 7d 20 28 45 75 72 6f 70 65 61 \q{#\,} (Europea
2020: 6e 20 73 74 79 6c 65 29 20 69 66 20 5c 71 7b 3c n style) if \q{<
2030: 63 6f 6d 6d 61 2d 73 65 70 3e 7d 20 69 73 20 61 comma-sep>} is a
2040: 6c 72 65 61 64 79 0a 5c 71 7b 23 5c 2e 7d 2e 0a lready.\q{#\.}..
2050: 0a 54 68 65 73 65 20 70 61 72 61 6d 65 74 65 72 .These parameter
2060: 73 20 6d 61 79 20 73 65 65 6d 20 75 6e 77 69 65 s may seem unwie
2070: 6c 64 79 2c 20 62 75 74 20 74 68 65 79 20 63 61 ldy, but they ca
2080: 6e 20 61 6c 73 6f 20 74 61 6b 65 20 74 68 65 69 n also take thei
2090: 72 0a 64 65 66 61 75 6c 74 73 20 66 72 6f 6d 20 r.defaults from
20a0: 73 74 61 74 65 20 76 61 72 69 61 62 6c 65 73 2c state variables,
20b0: 20 64 65 73 63 72 69 62 65 64 20 62 65 6c 6f 77 described below
20c0: 2e 0a 0a 5c 73 75 62 73 75 62 73 65 63 74 69 6f ...\subsubsectio
20d0: 6e 2a 7b 28 6e 75 6d 2f 63 6f 6d 6d 61 20 3c 6e n*{(num/comma <n
20e0: 3e 20 5b 3c 62 61 73 65 3e 20 3c 70 72 65 63 69 > [<base> <preci
20f0: 73 69 6f 6e 3e 20 3c 73 69 67 6e 3e 5d 29 7d 0a sion> <sign>])}.
2100: 0a 53 68 6f 72 74 63 75 74 20 66 6f 72 20 5c 71 .Shortcut for \q
2110: 7b 6e 75 6d 7d 20 74 6f 20 70 72 69 6e 74 20 77 {num} to print w
2120: 69 74 68 20 63 6f 6d 6d 61 73 2e 0a 0a 20 20 5c ith commas... \
2130: 71 7b 28 66 6d 74 20 23 66 20 28 6e 75 6d 2f 63 q{(fmt #f (num/c
2140: 6f 6d 6d 61 20 31 32 33 34 35 36 37 29 29 7d 0a omma 1234567))}.
2150: 0a 20 20 5c 71 7b 3d 3e 20 22 31 2c 32 33 34 2c . \q{=> "1,234,
2160: 35 36 37 22 7d 0a 0a 5c 73 75 62 73 75 62 73 65 567"}..\subsubse
2170: 63 74 69 6f 6e 2a 7b 28 6e 75 6d 2f 73 69 20 3c ction*{(num/si <
2180: 6e 3e 20 5b 3c 62 61 73 65 3e 20 3c 73 75 66 66 n> [<base> <suff
2190: 69 78 3e 5d 29 7d 0a 0a 41 62 62 72 65 76 69 61 ix>])}..Abbrevia
21a0: 74 65 73 20 5c 71 7b 3c 6e 3e 7d 20 77 69 74 68 tes \q{<n>} with
21b0: 20 61 6e 20 53 49 20 73 75 66 66 69 78 20 61 73 an SI suffix as
21c0: 20 69 6e 20 74 68 65 20 2d 68 20 6f 72 20 2d 2d in the -h or --
21d0: 73 69 20 6f 70 74 69 6f 6e 20 74 6f 0a 6d 61 6e si option to.man
21e0: 79 20 47 4e 55 20 63 6f 6d 6d 61 6e 64 73 2e 20 y GNU commands.
21f0: 20 54 68 65 20 62 61 73 65 20 64 65 66 61 75 6c The base defaul
2200: 74 73 20 74 6f 20 31 30 32 34 2c 20 75 73 69 6e ts to 1024, usin
2210: 67 20 73 75 66 66 69 78 20 6e 61 6d 65 73 0a 6c g suffix names.l
2220: 69 6b 65 20 4b 69 2c 20 4d 69 2c 20 47 69 2c 20 ike Ki, Mi, Gi,
2230: 65 74 63 2e 20 20 4f 74 68 65 72 20 62 61 73 65 etc. Other base
2240: 73 20 28 65 2e 67 2e 20 74 68 65 20 73 74 61 6e s (e.g. the stan
2250: 64 61 72 64 20 31 30 30 30 29 20 68 61 76 65 20 dard 1000) have
2260: 74 68 65 0a 73 75 66 66 69 78 65 73 20 6b 2c 20 the.suffixes k,
2270: 4d 2c 20 47 2c 20 65 74 63 2e 0a 0a 54 68 65 20 M, G, etc...The
2280: 5c 71 7b 3c 73 75 66 66 69 78 3e 7d 20 61 72 67 \q{<suffix>} arg
2290: 75 6d 65 6e 74 20 69 73 20 61 70 70 65 6e 64 65 ument is appende
22a0: 64 20 6f 6e 6c 79 20 69 66 20 61 6e 20 61 62 62 d only if an abb
22b0: 72 65 76 69 61 74 69 6f 6e 20 69 73 20 75 73 65 reviation is use
22c0: 64 2e 0a 0a 20 20 5c 71 7b 28 66 6d 74 20 23 66 d... \q{(fmt #f
22d0: 20 28 6e 75 6d 2f 73 69 20 36 30 38 29 29 7d 0a (num/si 608))}.
22e0: 0a 20 20 5c 71 7b 3d 3e 20 22 36 30 38 22 7d 0a . \q{=> "608"}.
22f0: 0a 20 20 5c 71 7b 28 66 6d 74 20 23 66 20 28 6e . \q{(fmt #f (n
2300: 75 6d 2f 73 69 20 33 39 38 36 29 29 7d 0a 0a 20 um/si 3986))}..
2310: 20 5c 71 7b 3d 3e 20 22 33 2e 39 4b 69 22 7d 0a \q{=> "3.9Ki"}.
2320: 0a 20 20 5c 71 7b 28 66 6d 74 20 23 66 20 28 6e . \q{(fmt #f (n
2330: 75 6d 2f 73 69 20 33 39 38 36 20 31 30 30 30 20 um/si 3986 1000
2340: 22 42 22 29 29 7d 0a 0a 20 20 5c 71 7b 3d 3e 20 "B"))}.. \q{=>
2350: 22 34 6b 42 22 7d 0a 0a 53 65 65 20 5c 75 72 6c "4kB"}..See \url
2360: 68 7b 68 74 74 70 3a 2f 2f 77 77 77 2e 62 69 70 h{http://www.bip
2370: 6d 2e 6f 72 67 2f 65 6e 2f 73 69 2f 73 69 5f 62 m.org/en/si/si_b
2380: 72 6f 63 68 75 72 65 2f 63 68 61 70 74 65 72 33 rochure/chapter3
2390: 2f 70 72 65 66 69 78 65 73 2e 68 74 6d 6c 7d 7b /prefixes.html}{
23a0: 68 74 74 70 3a 2f 2f 77 77 77 2e 62 69 70 6d 2e http://www.bipm.
23b0: 6f 72 67 2f 65 6e 2f 73 69 2f 73 69 5f 62 72 6f org/en/si/si_bro
23c0: 63 68 75 72 65 2f 63 68 61 70 74 65 72 33 2f 70 chure/chapter3/p
23d0: 72 65 66 69 78 65 73 2e 68 74 6d 6c 7d 2e 0a 0a refixes.html}...
23e0: 5c 73 75 62 73 75 62 73 65 63 74 69 6f 6e 2a 7b \subsubsection*{
23f0: 28 6e 75 6d 2f 66 69 74 20 3c 77 69 64 74 68 3e (num/fit <width>
2400: 20 3c 6e 3e 20 2e 20 3c 41 52 47 53 3e 29 7d 0a <n> . <ARGS>)}.
2410: 0a 4c 69 6b 65 20 5c 71 7b 6e 75 6d 7d 2c 20 62 .Like \q{num}, b
2420: 75 74 20 69 66 20 74 68 65 20 72 65 73 75 6c 74 ut if the result
2430: 20 64 6f 65 73 6e 27 74 20 66 69 74 20 69 6e 20 doesn't fit in
2440: 5c 71 7b 3c 77 69 64 74 68 3e 7d 2c 20 6f 75 74 \q{<width>}, out
2450: 70 75 74 0a 69 6e 73 74 65 61 64 20 61 20 73 74 put.instead a st
2460: 72 69 6e 67 20 6f 66 20 68 61 73 68 65 73 20 28 ring of hashes (
2470: 77 69 74 68 20 74 68 65 20 63 75 72 72 65 6e 74 with the current
2480: 20 5c 71 7b 3c 70 72 65 63 69 73 69 6f 6e 3e 7d \q{<precision>}
2490: 29 20 72 61 74 68 65 72 0a 74 68 61 6e 20 73 68 ) rather.than sh
24a0: 6f 77 69 6e 67 20 61 6e 20 69 6e 63 6f 72 72 65 owing an incorre
24b0: 63 74 6c 79 20 74 72 75 6e 63 61 74 65 64 20 6e ctly truncated n
24c0: 75 6d 62 65 72 2e 20 20 46 6f 72 20 65 78 61 6d umber. For exam
24d0: 70 6c 65 0a 0a 20 20 5c 71 7b 28 66 6d 74 20 23 ple.. \q{(fmt #
24e0: 66 20 28 66 69 78 20 32 20 28 6e 75 6d 2f 66 69 f (fix 2 (num/fi
24f0: 74 20 34 20 31 32 2e 33 34 35 29 29 29 7d 0a 20 t 4 12.345)))}.
2500: 20 5c 71 7b 3d 3e 20 22 23 2e 23 23 22 7d 0a 0a \q{=> "#.##"}..
2510: 5c 73 75 62 73 75 62 73 65 63 74 69 6f 6e 2a 7b \subsubsection*{
2520: 28 6e 75 6d 2f 72 6f 6d 61 6e 20 3c 6e 3e 29 7d (num/roman <n>)}
2530: 0a 0a 46 6f 72 6d 61 74 73 20 74 68 65 20 6e 75 ..Formats the nu
2540: 6d 62 65 72 20 61 73 20 61 20 52 6f 6d 61 6e 20 mber as a Roman
2550: 6e 75 6d 65 72 61 6c 3a 0a 0a 20 20 5c 71 7b 28 numeral:.. \q{(
2560: 66 6d 74 20 23 66 20 28 6e 75 6d 2f 72 6f 6d 61 fmt #f (num/roma
2570: 6e 20 31 39 38 39 29 29 7d 0a 20 20 5c 71 7b 3d n 1989))}. \q{=
2580: 3e 20 22 4d 43 4d 4c 58 58 58 49 58 22 7d 0a 0a > "MCMLXXXIX"}..
2590: 5c 73 75 62 73 75 62 73 65 63 74 69 6f 6e 2a 7b \subsubsection*{
25a0: 28 6e 75 6d 2f 6f 6c 64 2d 72 6f 6d 61 6e 20 3c (num/old-roman <
25b0: 6e 3e 29 7d 0a 0a 46 6f 72 6d 61 74 73 20 74 68 n>)}..Formats th
25c0: 65 20 6e 75 6d 62 65 72 20 61 73 20 61 6e 20 6f e number as an o
25d0: 6c 64 2d 73 74 79 6c 65 20 52 6f 6d 61 6e 20 6e ld-style Roman n
25e0: 75 6d 65 72 61 6c 2c 20 77 69 74 68 6f 75 74 20 umeral, without
25f0: 74 68 65 0a 73 75 62 74 72 61 63 74 69 6f 6e 20 the.subtraction
2600: 61 62 62 72 65 76 69 61 74 69 6f 6e 20 72 75 6c abbreviation rul
2610: 65 3a 0a 0a 20 20 5c 71 7b 28 66 6d 74 20 23 66 e:.. \q{(fmt #f
2620: 20 28 6e 75 6d 2f 6f 6c 64 2d 72 6f 6d 61 6e 20 (num/old-roman
2630: 31 39 38 39 29 29 7d 0a 20 20 5c 71 7b 3d 3e 20 1989))}. \q{=>
2640: 22 4d 44 43 43 43 43 4c 58 58 58 56 49 49 49 49 "MDCCCCLXXXVIIII
2650: 22 7d 0a 0a 0a 5c 73 75 62 73 65 63 74 69 6f 6e "}...\subsection
2660: 7b 46 6f 72 6d 61 74 74 69 6e 67 20 53 70 61 63 {Formatting Spac
2670: 65 7d 0a 0a 5c 73 75 62 73 75 62 73 65 63 74 69 e}..\subsubsecti
2680: 6f 6e 2a 7b 6e 6c 7d 0a 0a 4f 75 74 70 75 74 73 on*{nl}..Outputs
2690: 20 61 20 6e 65 77 6c 69 6e 65 2e 0a 0a 5c 73 75 a newline...\su
26a0: 62 73 75 62 73 65 63 74 69 6f 6e 2a 7b 66 6c 7d bsubsection*{fl}
26b0: 0a 0a 53 68 6f 72 74 20 66 6f 72 20 22 66 72 65 ..Short for "fre
26c0: 73 68 20 6c 69 6e 65 2c 22 20 6f 75 74 70 75 74 sh line," output
26d0: 73 20 61 20 6e 65 77 6c 69 6e 65 20 6f 6e 6c 79 s a newline only
26e0: 20 69 66 20 77 65 27 72 65 20 6e 6f 74 20 61 6c if we're not al
26f0: 72 65 61 64 79 0a 61 74 20 74 68 65 20 73 74 61 ready.at the sta
2700: 72 74 20 6f 66 20 61 20 6c 69 6e 65 2e 0a 0a 5c rt of a line...\
2710: 73 75 62 73 75 62 73 65 63 74 69 6f 6e 2a 7b 28 subsubsection*{(
2720: 73 70 61 63 65 2d 74 6f 20 3c 63 6f 6c 75 6d 6e space-to <column
2730: 3e 29 7d 0a 0a 4f 75 74 70 75 74 73 20 73 70 61 >)}..Outputs spa
2740: 63 65 73 20 75 70 20 74 6f 20 74 68 65 20 67 69 ces up to the gi
2750: 76 65 6e 20 5c 71 7b 3c 63 6f 6c 75 6d 6e 3e 7d ven \q{<column>}
2760: 2e 20 20 49 66 20 74 68 65 20 63 75 72 72 65 6e . If the curren
2770: 74 20 63 6f 6c 75 6d 6e 20 69 73 0a 61 6c 72 65 t column is.alre
2780: 61 64 79 20 3e 3d 20 5c 71 7b 3c 63 6f 6c 75 6d ady >= \q{<colum
2790: 6e 3e 7d 2c 20 64 6f 65 73 20 6e 6f 74 68 69 6e n>}, does nothin
27a0: 67 2e 0a 0a 5c 73 75 62 73 75 62 73 65 63 74 69 g...\subsubsecti
27b0: 6f 6e 2a 7b 28 74 61 62 2d 74 6f 20 5b 3c 74 61 on*{(tab-to [<ta
27c0: 62 2d 77 69 64 74 68 3e 5d 29 7d 0a 0a 4f 75 74 b-width>])}..Out
27d0: 70 75 74 73 20 73 70 61 63 65 73 20 75 70 20 74 puts spaces up t
27e0: 6f 20 74 68 65 20 6e 65 78 74 20 74 61 62 20 73 o the next tab s
27f0: 74 6f 70 2c 20 75 73 69 6e 67 20 74 61 62 20 73 top, using tab s
2800: 74 6f 70 73 20 6f 66 20 77 69 64 74 68 0a 5c 71 tops of width.\q
2810: 7b 3c 74 61 62 2d 77 69 64 74 68 3e 7d 2c 20 77 {<tab-width>}, w
2820: 68 69 63 68 20 64 65 66 61 75 6c 74 73 20 74 6f hich defaults to
2830: 20 38 2e 20 20 49 66 20 61 6c 72 65 61 64 79 20 8. If already
2840: 6f 6e 20 61 20 74 61 62 20 73 74 6f 70 2c 20 64 on a tab stop, d
2850: 6f 65 73 0a 6e 6f 74 68 69 6e 67 2e 20 20 49 66 oes.nothing. If
2860: 20 79 6f 75 20 77 61 6e 74 20 74 6f 20 65 6e 73 you want to ens
2870: 75 72 65 20 79 6f 75 20 61 6c 77 61 79 73 20 74 ure you always t
2880: 61 62 20 61 74 20 6c 65 61 73 74 20 6f 6e 65 20 ab at least one
2890: 73 70 61 63 65 2c 20 79 6f 75 0a 63 61 6e 20 75 space, you.can u
28a0: 73 65 20 5c 71 7b 28 63 61 74 20 22 20 22 20 28 se \q{(cat " " (
28b0: 74 61 62 2d 74 6f 20 77 69 64 74 68 29 29 7d 2e tab-to width))}.
28c0: 0a 0a 5c 73 75 62 73 75 62 73 65 63 74 69 6f 6e ..\subsubsection
28d0: 2a 7b 66 6d 74 2d 6e 75 6c 6c 7d 0a 0a 4f 75 74 *{fmt-null}..Out
28e0: 70 75 74 73 20 6e 6f 74 68 69 6e 67 20 28 75 73 puts nothing (us
28f0: 65 66 75 6c 20 69 6e 20 63 6f 6d 62 69 6e 61 74 eful in combinat
2900: 6f 72 73 20 61 6e 64 20 61 73 20 61 20 64 65 66 ors and as a def
2910: 61 75 6c 74 20 6e 6f 6f 70 20 69 6e 0a 63 6f 6e ault noop in.con
2920: 64 69 74 69 6f 6e 61 6c 73 29 2e 0a 0a 0a 5c 73 ditionals)....\s
2930: 75 62 73 65 63 74 69 6f 6e 7b 43 6f 6e 63 61 74 ubsection{Concat
2940: 65 6e 61 74 69 6f 6e 7d 0a 0a 5c 73 75 62 73 75 enation}..\subsu
2950: 62 73 65 63 74 69 6f 6e 2a 7b 28 63 61 74 20 3c bsection*{(cat <
2960: 66 6f 72 6d 61 74 3e 20 2e 2e 2e 29 7d 0a 0a 43 format> ...)}..C
2970: 6f 6e 63 61 74 65 6e 61 74 65 73 20 74 68 65 20 oncatenates the
2980: 6f 75 74 70 75 74 20 6f 66 20 65 61 63 68 20 5c output of each \
2990: 71 7b 3c 66 6f 72 6d 61 74 3e 7d 2e 0a 0a 5c 73 q{<format>}...\s
29a0: 75 62 73 75 62 73 65 63 74 69 6f 6e 2a 7b 28 61 ubsubsection*{(a
29b0: 70 70 6c 79 2d 63 61 74 20 3c 6c 69 73 74 3e 29 pply-cat <list>)
29c0: 7d 0a 0a 45 71 75 69 76 61 6c 65 6e 74 20 74 6f }..Equivalent to
29d0: 20 5c 71 7b 28 61 70 70 6c 79 20 63 61 74 20 3c \q{(apply cat <
29e0: 6c 69 73 74 3e 29 7d 20 62 75 74 20 6d 61 79 20 list>)} but may
29f0: 62 65 20 6d 6f 72 65 20 65 66 66 69 63 69 65 6e be more efficien
2a00: 74 2e 0a 0a 5c 73 75 62 73 75 62 73 65 63 74 69 t...\subsubsecti
2a10: 6f 6e 2a 7b 28 66 6d 74 2d 6a 6f 69 6e 20 3c 66 on*{(fmt-join <f
2a20: 6f 72 6d 61 74 74 65 72 3e 20 3c 6c 69 73 74 3e ormatter> <list>
2a30: 20 5b 3c 73 65 70 3e 5d 29 7d 0a 0a 46 6f 72 6d [<sep>])}..Form
2a40: 61 74 73 20 65 61 63 68 20 65 6c 65 6d 65 6e 74 ats each element
2a50: 20 5c 71 7b 3c 65 6c 74 3e 7d 20 6f 66 20 5c 71 \q{<elt>} of \q
2a60: 7b 3c 6c 69 73 74 3e 7d 20 77 69 74 68 20 5c 71 {<list>} with \q
2a70: 7b 28 3c 66 6f 72 6d 61 74 74 65 72 3e 0a 3c 65 {(<formatter>.<e
2a80: 6c 74 3e 29 7d 2c 20 69 6e 73 65 72 74 69 6e 67 lt>)}, inserting
2a90: 20 5c 71 7b 3c 73 65 70 3e 7d 20 69 6e 20 62 65 \q{<sep>} in be
2aa0: 74 77 65 65 6e 2e 20 20 5c 71 7b 3c 73 65 70 3e tween. \q{<sep>
2ab0: 7d 20 64 65 66 61 75 6c 74 73 20 74 6f 20 74 68 } defaults to th
2ac0: 65 0a 65 6d 70 74 79 20 73 74 72 69 6e 67 2c 20 e.empty string,
2ad0: 62 75 74 20 63 61 6e 20 62 65 20 61 6e 79 20 66 but can be any f
2ae0: 6f 72 6d 61 74 2e 0a 0a 20 20 5c 71 7b 28 66 6d ormat... \q{(fm
2af0: 74 20 23 66 20 28 66 6d 74 2d 6a 6f 69 6e 20 64 t #f (fmt-join d
2b00: 73 70 20 27 28 61 20 62 20 63 29 20 22 2c 20 22 sp '(a b c) ", "
2b10: 29 29 7d 0a 0a 20 20 5c 71 7b 3d 3e 20 22 61 2c ))}.. \q{=> "a,
2b20: 20 62 2c 20 63 22 7d 0a 0a 5c 73 75 62 73 75 62 b, c"}..\subsub
2b30: 73 65 63 74 69 6f 6e 2a 7b 28 66 6d 74 2d 6a 6f section*{(fmt-jo
2b40: 69 6e 2f 70 72 65 66 69 78 20 3c 66 6f 72 6d 61 in/prefix <forma
2b50: 74 74 65 72 3e 20 3c 6c 69 73 74 3e 20 5b 3c 73 tter> <list> [<s
2b60: 65 70 3e 5d 29 7d 0a 5c 73 75 62 73 75 62 73 65 ep>])}.\subsubse
2b70: 63 74 69 6f 6e 2a 7b 28 66 6d 74 2d 6a 6f 69 6e ction*{(fmt-join
2b80: 2f 73 75 66 66 69 78 20 3c 66 6f 72 6d 61 74 74 /suffix <formatt
2b90: 65 72 3e 20 3c 6c 69 73 74 3e 20 5b 3c 73 65 70 er> <list> [<sep
2ba0: 3e 5d 29 7d 0a 0a 20 20 5c 71 7b 28 66 6d 74 20 >])}.. \q{(fmt
2bb0: 23 66 20 28 66 6d 74 2d 6a 6f 69 6e 2f 70 72 65 #f (fmt-join/pre
2bc0: 66 69 78 20 64 73 70 20 27 28 75 73 72 20 6c 6f fix dsp '(usr lo
2bd0: 63 61 6c 20 62 69 6e 29 20 22 2f 22 29 29 7d 0a cal bin) "/"))}.
2be0: 0a 20 20 5c 71 7b 3d 3e 20 22 2f 75 73 72 2f 6c . \q{=> "/usr/l
2bf0: 6f 63 61 6c 2f 62 69 6e 22 7d 0a 0a 41 73 20 5c ocal/bin"}..As \
2c00: 71 7b 66 6d 74 2d 6a 6f 69 6e 7d 2c 20 62 75 74 q{fmt-join}, but
2c10: 20 69 6e 73 65 72 74 73 20 5c 71 7b 3c 73 65 70 inserts \q{<sep
2c20: 3e 7d 20 62 65 66 6f 72 65 2f 61 66 74 65 72 20 >} before/after
2c30: 65 76 65 72 79 20 65 6c 65 6d 65 6e 74 2e 0a 0a every element...
2c40: 5c 73 75 62 73 75 62 73 65 63 74 69 6f 6e 2a 7b \subsubsection*{
2c50: 28 66 6d 74 2d 6a 6f 69 6e 2f 6c 61 73 74 20 3c (fmt-join/last <
2c60: 66 6f 72 6d 61 74 74 65 72 3e 20 3c 6c 61 73 74 formatter> <last
2c70: 2d 66 6f 72 6d 61 74 74 65 72 3e 20 3c 6c 69 73 -formatter> <lis
2c80: 74 3e 20 5b 3c 73 65 70 3e 5d 29 7d 0a 0a 41 73 t> [<sep>])}..As
2c90: 20 5c 71 7b 66 6d 74 2d 6a 6f 69 6e 7d 2c 20 62 \q{fmt-join}, b
2ca0: 75 74 20 74 68 65 20 6c 61 73 74 20 65 6c 65 6d ut the last elem
2cb0: 65 6e 74 20 6f 66 20 74 68 65 20 6c 69 73 74 20 ent of the list
2cc0: 69 73 20 66 6f 72 6d 61 74 74 65 64 20 77 69 74 is formatted wit
2cd0: 68 0a 5c 71 7b 3c 6c 61 73 74 2d 66 6f 72 6d 61 h.\q{<last-forma
2ce0: 74 74 65 72 3e 7d 20 69 6e 73 74 65 61 64 2e 0a tter>} instead..
2cf0: 0a 5c 73 75 62 73 75 62 73 65 63 74 69 6f 6e 2a .\subsubsection*
2d00: 7b 28 66 6d 74 2d 6a 6f 69 6e 2f 64 6f 74 20 3c {(fmt-join/dot <
2d10: 66 6f 72 6d 61 74 74 65 72 3e 20 3c 64 6f 74 2d formatter> <dot-
2d20: 66 6f 72 6d 61 74 74 65 72 3e 20 3c 6c 69 73 74 formatter> <list
2d30: 3e 20 5b 3c 73 65 70 3e 5d 29 7d 0a 0a 41 73 20 > [<sep>])}..As
2d40: 5c 71 7b 66 6d 74 2d 6a 6f 69 6e 7d 2c 20 62 75 \q{fmt-join}, bu
2d50: 74 20 69 66 20 74 68 65 20 6c 69 73 74 20 69 73 t if the list is
2d60: 20 61 20 64 6f 74 74 65 64 20 6c 69 73 74 2c 20 a dotted list,
2d70: 74 68 65 6e 20 66 6f 72 6d 61 74 73 20 74 68 65 then formats the
2d80: 20 64 6f 74 74 65 64 0a 76 61 6c 75 65 20 77 69 dotted.value wi
2d90: 74 68 20 5c 71 7b 3c 64 6f 74 2d 66 6f 72 6d 61 th \q{<dot-forma
2da0: 74 74 65 72 3e 7d 20 69 6e 73 74 65 61 64 2e 0a tter>} instead..
2db0: 0a 0a 5c 73 75 62 73 65 63 74 69 6f 6e 7b 50 61 ..\subsection{Pa
2dc0: 64 64 69 6e 67 20 61 6e 64 20 54 72 69 6d 6d 69 dding and Trimmi
2dd0: 6e 67 7d 0a 0a 5c 73 75 62 73 75 62 73 65 63 74 ng}..\subsubsect
2de0: 69 6f 6e 2a 7b 28 70 61 64 20 3c 77 69 64 74 68 ion*{(pad <width
2df0: 3e 20 3c 66 6f 72 6d 61 74 3e 20 2e 2e 2e 29 7d > <format> ...)}
2e00: 0a 5c 73 75 62 73 75 62 73 65 63 74 69 6f 6e 2a .\subsubsection*
2e10: 7b 28 70 61 64 2f 6c 65 66 74 20 3c 77 69 64 74 {(pad/left <widt
2e20: 68 3e 20 3c 66 6f 72 6d 61 74 3e 20 2e 2e 2e 29 h> <format> ...)
2e30: 7d 0a 5c 73 75 62 73 75 62 73 65 63 74 69 6f 6e }.\subsubsection
2e40: 2a 7b 28 70 61 64 2f 62 6f 74 68 20 3c 77 69 64 *{(pad/both <wid
2e50: 74 68 3e 20 3c 66 6f 72 6d 61 74 3e 20 2e 2e 2e th> <format> ...
2e60: 29 7d 0a 0a 41 6e 61 6c 6f 67 73 20 6f 66 20 53 )}..Analogs of S
2e70: 52 46 49 2d 31 33 20 5c 71 7b 73 74 72 69 6e 67 RFI-13 \q{string
2e80: 2d 70 61 64 7d 2c 20 74 68 65 73 65 20 61 64 64 -pad}, these add
2e90: 20 65 78 74 72 61 20 73 70 61 63 65 20 74 6f 20 extra space to
2ea0: 74 68 65 20 6c 65 66 74 2c 0a 72 69 67 68 74 20 the left,.right
2eb0: 6f 72 20 62 6f 74 68 20 73 69 64 65 73 20 6f 66 or both sides of
2ec0: 20 74 68 65 20 6f 75 74 70 75 74 20 67 65 6e 65 the output gene
2ed0: 72 61 74 65 64 20 62 79 20 74 68 65 20 5c 71 7b rated by the \q{
2ee0: 3c 66 6f 72 6d 61 74 3e 7d 73 20 74 6f 0a 70 61 <format>}s to.pa
2ef0: 64 20 69 74 20 74 6f 20 5c 71 7b 3c 77 69 64 74 d it to \q{<widt
2f00: 68 3e 7d 2e 20 20 49 66 20 5c 71 7b 3c 77 69 64 h>}. If \q{<wid
2f10: 74 68 3e 7d 20 69 73 20 65 78 63 65 65 64 65 64 th>} is exceeded
2f20: 20 68 61 73 20 6e 6f 20 65 66 66 65 63 74 2e 0a has no effect..
2f30: 5c 71 7b 70 61 64 2f 62 6f 74 68 7d 20 77 69 6c \q{pad/both} wil
2f40: 6c 20 69 6e 63 6c 75 64 65 20 61 6e 20 65 78 74 l include an ext
2f50: 72 61 20 73 70 61 63 65 20 6f 6e 20 74 68 65 20 ra space on the
2f60: 72 69 67 68 74 20 73 69 64 65 20 6f 66 20 74 68 right side of th
2f70: 65 0a 6f 75 74 70 75 74 20 69 66 20 74 68 65 20 e.output if the
2f80: 64 69 66 66 65 72 65 6e 63 65 20 69 73 20 6f 64 difference is od
2f90: 64 2e 0a 0a 5c 71 7b 70 61 64 7d 20 64 6f 65 73 d...\q{pad} does
2fa0: 20 6e 6f 74 20 61 63 63 75 6d 75 6c 61 74 65 20 not accumulate
2fb0: 61 6e 79 20 69 6e 74 65 72 6d 65 64 69 61 74 65 any intermediate
2fc0: 20 64 61 74 61 2e 0a 0a 4e 6f 74 65 20 74 68 65 data...Note the
2fd0: 73 65 20 61 72 65 20 63 6f 6c 75 6d 6e 2d 6f 72 se are column-or
2fe0: 69 65 6e 74 65 64 20 70 61 64 64 65 72 73 2c 20 iented padders,
2ff0: 73 6f 20 77 6f 6e 27 74 20 6e 65 63 65 73 73 61 so won't necessa
3000: 72 69 6c 79 20 77 6f 72 6b 0a 77 69 74 68 20 6d rily work.with m
3010: 75 6c 74 69 2d 6c 69 6e 65 20 6f 75 74 70 75 74 ulti-line output
3020: 20 28 70 61 64 64 69 6e 67 20 64 6f 65 73 6e 27 (padding doesn'
3030: 74 20 73 65 65 6d 20 61 20 6c 69 6b 65 6c 79 20 t seem a likely
3040: 6f 70 65 72 61 74 69 6f 6e 20 66 6f 72 0a 6d 75 operation for.mu
3050: 6c 74 69 2d 6c 69 6e 65 20 6f 75 74 70 75 74 29 lti-line output)
3060: 2e 0a 0a 5c 73 75 62 73 75 62 73 65 63 74 69 6f ...\subsubsectio
3070: 6e 2a 7b 28 74 72 69 6d 20 3c 77 69 64 74 68 3e n*{(trim <width>
3080: 20 3c 66 6f 72 6d 61 74 3e 20 2e 2e 2e 29 7d 0a <format> ...)}.
3090: 5c 73 75 62 73 75 62 73 65 63 74 69 6f 6e 2a 7b \subsubsection*{
30a0: 28 74 72 69 6d 2f 6c 65 66 74 20 3c 77 69 64 74 (trim/left <widt
30b0: 68 3e 20 3c 66 6f 72 6d 61 74 3e 20 2e 2e 2e 29 h> <format> ...)
30c0: 7d 0a 5c 73 75 62 73 75 62 73 65 63 74 69 6f 6e }.\subsubsection
30d0: 2a 7b 28 74 72 69 6d 2f 62 6f 74 68 20 3c 77 69 *{(trim/both <wi
30e0: 64 74 68 3e 20 3c 66 6f 72 6d 61 74 3e 20 2e 2e dth> <format> ..
30f0: 2e 29 7d 0a 0a 41 6e 61 6c 6f 67 73 20 6f 66 20 .)}..Analogs of
3100: 53 52 46 49 2d 31 33 20 5c 71 7b 73 74 72 69 6e SRFI-13 \q{strin
3110: 67 2d 74 72 69 6d 7d 2c 20 74 72 75 6e 63 61 74 g-trim}, truncat
3120: 65 73 20 74 68 65 20 6f 75 74 70 75 74 20 6f 66 es the output of
3130: 20 74 68 65 0a 5c 71 7b 3c 66 6f 72 6d 61 74 3e the.\q{<format>
3140: 7d 73 20 74 6f 20 66 6f 72 63 65 20 69 74 20 69 }s to force it i
3150: 6e 20 75 6e 64 65 72 20 5c 71 7b 3c 77 69 64 74 n under \q{<widt
3160: 68 3e 7d 20 63 6f 6c 75 6d 6e 73 2e 20 20 41 73 h>} columns. As
3170: 20 73 6f 6f 6e 20 61 73 0a 61 6e 79 20 6f 66 20 soon as.any of
3180: 74 68 65 20 5c 71 7b 3c 66 6f 72 6d 61 74 3e 7d the \q{<format>}
3190: 73 20 65 78 63 65 65 64 20 5c 71 7b 3c 77 69 64 s exceed \q{<wid
31a0: 74 68 3e 7d 2c 20 73 74 6f 70 20 66 6f 72 6d 61 th>}, stop forma
31b0: 74 74 69 6e 67 20 61 6e 64 0a 74 72 75 6e 63 61 tting and.trunca
31c0: 74 65 20 74 68 65 20 72 65 73 75 6c 74 2c 20 72 te the result, r
31d0: 65 74 75 72 6e 69 6e 67 20 63 6f 6e 74 72 6f 6c eturning control
31e0: 20 74 6f 20 77 68 6f 65 76 65 72 20 63 61 6c 6c to whoever call
31f0: 65 64 20 5c 71 7b 74 72 69 6d 7d 2e 20 20 49 66 ed \q{trim}. If
3200: 0a 5c 71 7b 3c 77 69 64 74 68 3e 7d 20 69 73 20 .\q{<width>} is
3210: 6e 6f 74 20 65 78 63 65 65 64 65 64 20 68 61 73 not exceeded has
3220: 20 6e 6f 20 65 66 66 65 63 74 2e 0a 0a 49 66 20 no effect...If
3230: 61 20 74 72 75 6e 63 61 74 69 6f 6e 20 65 6c 6c a truncation ell
3240: 69 70 73 65 20 69 73 20 73 65 74 20 28 65 2e 67 ipse is set (e.g
3250: 2e 20 77 69 74 68 20 74 68 65 20 5c 71 7b 65 6c . with the \q{el
3260: 6c 69 70 73 65 73 7d 20 70 72 6f 63 65 64 75 72 lipses} procedur
3270: 65 0a 62 65 6c 6f 77 29 2c 20 74 68 65 6e 20 77 e.below), then w
3280: 68 65 6e 20 61 6e 79 20 74 72 75 6e 63 61 74 69 hen any truncati
3290: 6f 6e 20 6f 63 63 75 72 73 20 5c 71 7b 74 72 69 on occurs \q{tri
32a0: 6d 7d 20 61 6e 64 20 5c 71 7b 74 72 69 6d 2f 6c m} and \q{trim/l
32b0: 65 66 74 7d 0a 77 69 6c 6c 20 61 70 70 65 6e 64 eft}.will append
32c0: 20 61 6e 64 20 70 72 65 70 65 6e 64 20 74 68 65 and prepend the
32d0: 20 65 6c 6c 69 70 73 65 2c 20 72 65 73 70 65 63 ellipse, respec
32e0: 74 69 76 65 6c 79 2e 20 20 5c 71 7b 74 72 69 6d tively. \q{trim
32f0: 2f 62 6f 74 68 7d 20 77 69 6c 6c 0a 62 6f 74 68 /both} will.both
3300: 20 70 72 65 70 65 6e 64 20 61 6e 64 20 61 70 70 prepend and app
3310: 65 6e 64 2e 20 20 54 68 65 20 6c 65 6e 67 74 68 end. The length
3320: 20 6f 66 20 74 68 65 20 65 6c 6c 69 70 73 65 20 of the ellipse
3330: 77 69 6c 6c 20 62 65 20 63 6f 6e 73 69 64 65 72 will be consider
3340: 65 64 0a 77 68 65 6e 20 74 72 75 6e 63 61 74 69 ed.when truncati
3350: 6e 67 20 74 68 65 20 6f 72 69 67 69 6e 61 6c 20 ng the original
3360: 73 74 72 69 6e 67 2c 20 73 6f 20 74 68 61 74 20 string, so that
3370: 74 68 65 20 74 6f 74 61 6c 20 77 69 64 74 68 20 the total width
3380: 77 69 6c 6c 0a 6e 65 76 65 72 20 62 65 20 6c 6f will.never be lo
3390: 6e 67 65 72 20 74 68 61 6e 20 5c 71 7b 3c 77 69 nger than \q{<wi
33a0: 64 74 68 3e 7d 2e 0a 0a 20 5c 71 7b 28 66 6d 74 dth>}... \q{(fmt
33b0: 20 23 66 20 28 65 6c 6c 69 70 73 65 73 20 22 2e #f (ellipses ".
33c0: 2e 2e 22 20 28 74 72 69 6d 20 35 20 22 61 62 63 .." (trim 5 "abc
33d0: 64 65 22 29 29 29 7d 0a 0a 20 5c 71 7b 3d 3e 20 de")))}.. \q{=>
33e0: 20 22 61 62 63 64 65 22 7d 0a 0a 20 5c 71 7b 28 "abcde"}.. \q{(
33f0: 66 6d 74 20 23 66 20 28 65 6c 6c 69 70 73 65 73 fmt #f (ellipses
3400: 20 22 2e 2e 2e 22 20 28 74 72 69 6d 20 35 20 22 "..." (trim 5 "
3410: 61 62 63 64 65 66 22 29 29 29 7d 0a 0a 20 5c 71 abcdef")))}.. \q
3420: 7b 3d 3e 20 20 22 61 62 2e 2e 2e 22 7d 0a 0a 5c {=> "ab..."}..\
3430: 73 75 62 73 75 62 73 65 63 74 69 6f 6e 2a 7b 28 subsubsection*{(
3440: 74 72 69 6d 2f 6c 65 6e 67 74 68 20 3c 77 69 64 trim/length <wid
3450: 74 68 3e 20 3c 66 6f 72 6d 61 74 3e 20 2e 2e 2e th> <format> ...
3460: 29 7d 0a 0a 41 20 76 61 72 69 61 6e 74 20 6f 66 )}..A variant of
3470: 20 5c 71 7b 74 72 69 6d 7d 20 77 68 69 63 68 20 \q{trim} which
3480: 61 63 74 73 20 6f 6e 20 74 68 65 20 61 63 74 75 acts on the actu
3490: 61 6c 20 63 68 61 72 61 63 74 65 72 20 63 6f 75 al character cou
34a0: 6e 74 20 72 61 74 68 65 72 0a 74 68 61 6e 20 63 nt rather.than c
34b0: 6f 6c 75 6d 6e 73 2c 20 75 73 65 66 75 6c 20 66 olumns, useful f
34c0: 6f 72 20 74 72 75 6e 63 61 74 69 6e 67 20 70 6f or truncating po
34d0: 74 65 6e 74 69 61 6c 6c 79 20 63 79 63 6c 69 63 tentially cyclic
34e0: 20 64 61 74 61 2e 0a 0a 5c 73 75 62 73 75 62 73 data...\subsubs
34f0: 65 63 74 69 6f 6e 2a 7b 28 66 69 74 20 3c 77 69 ection*{(fit <wi
3500: 64 74 68 3e 20 3c 66 6f 72 6d 61 74 3e 20 2e 2e dth> <format> ..
3510: 2e 29 7d 0a 5c 73 75 62 73 75 62 73 65 63 74 69 .)}.\subsubsecti
3520: 6f 6e 2a 7b 28 66 69 74 2f 6c 65 66 74 20 3c 77 on*{(fit/left <w
3530: 69 64 74 68 3e 20 3c 66 6f 72 6d 61 74 3e 20 2e idth> <format> .
3540: 2e 2e 29 7d 0a 5c 73 75 62 73 75 62 73 65 63 74 ..)}.\subsubsect
3550: 69 6f 6e 2a 7b 28 66 69 74 2f 62 6f 74 68 20 3c ion*{(fit/both <
3560: 77 69 64 74 68 3e 20 3c 66 6f 72 6d 61 74 3e 20 width> <format>
3570: 2e 2e 2e 29 7d 0a 0a 41 20 63 6f 6d 62 69 6e 61 ...)}..A combina
3580: 74 69 6f 6e 20 6f 66 20 5c 71 7b 70 61 64 7d 20 tion of \q{pad}
3590: 61 6e 64 20 5c 71 7b 74 72 75 6e 63 7d 2c 20 65 and \q{trunc}, e
35a0: 6e 73 75 72 65 73 20 74 68 65 20 6f 75 74 70 75 nsures the outpu
35b0: 74 20 77 69 64 74 68 20 69 73 0a 65 78 61 63 74 t width is.exact
35c0: 6c 79 20 5c 71 7b 3c 77 69 64 74 68 3e 7d 2c 20 ly \q{<width>},
35d0: 74 72 75 6e 63 61 74 69 6e 67 20 69 66 20 69 74 truncating if it
35e0: 20 67 6f 65 73 20 6f 76 65 72 20 61 6e 64 20 70 goes over and p
35f0: 61 64 64 69 6e 67 20 69 66 20 69 74 20 67 6f 65 adding if it goe
3600: 73 0a 75 6e 64 65 72 2e 0a 0a 0a 5c 73 75 62 73 s.under....\subs
3610: 65 63 74 69 6f 6e 7b 46 6f 72 6d 61 74 20 56 61 ection{Format Va
3620: 72 69 61 62 6c 65 73 7d 0a 0a 59 6f 75 20 6d 61 riables}..You ma
3630: 79 20 68 61 76 65 20 6e 6f 74 69 63 65 64 20 6d y have noticed m
3640: 61 6e 79 20 6f 66 20 74 68 65 20 66 6f 72 6d 61 any of the forma
3650: 74 74 65 72 73 20 61 72 65 20 61 77 61 72 65 20 tters are aware
3660: 6f 66 20 74 68 65 20 63 75 72 72 65 6e 74 0a 63 of the current.c
3670: 6f 6c 75 6d 6e 2e 20 20 54 68 69 73 20 69 73 20 olumn. This is
3680: 62 65 63 61 75 73 65 20 65 61 63 68 20 63 6f 6d because each com
3690: 62 69 6e 61 74 6f 72 20 69 73 20 61 63 74 75 61 binator is actua
36a0: 6c 6c 79 20 61 20 70 72 6f 63 65 64 75 72 65 20 lly a procedure
36b0: 6f 66 0a 6f 6e 65 20 61 72 67 75 6d 65 6e 74 2c of.one argument,
36c0: 20 74 68 65 20 63 75 72 72 65 6e 74 20 66 6f 72 the current for
36d0: 6d 61 74 20 73 74 61 74 65 2c 20 77 68 69 63 68 mat state, which
36e0: 20 68 6f 6c 64 73 20 62 61 73 69 63 0a 69 6e 66 holds basic.inf
36f0: 6f 72 6d 61 74 69 6f 6e 20 73 75 63 68 20 61 73 ormation such as
3700: 20 74 68 65 20 72 6f 77 2c 20 63 6f 6c 75 6d 6e the row, column
3710: 2c 20 61 6e 64 20 61 6e 79 20 6f 74 68 65 72 20 , and any other
3720: 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 74 68 61 74 information that
3730: 0a 61 20 66 6f 72 6d 61 74 20 63 6f 6d 62 69 6e .a format combin
3740: 61 74 6f 72 20 6d 61 79 20 77 61 6e 74 20 74 6f ator may want to
3750: 20 6b 65 65 70 20 74 72 61 63 6b 20 6f 66 2e 20 keep track of.
3760: 20 54 68 65 20 62 61 73 69 63 20 69 6e 74 65 72 The basic inter
3770: 66 61 63 65 0a 69 73 3a 0a 0a 5c 73 75 62 73 75 face.is:..\subsu
3780: 62 73 65 63 74 69 6f 6e 2a 7b 28 66 6d 74 2d 6c bsection*{(fmt-l
3790: 65 74 20 3c 6e 61 6d 65 3e 20 3c 76 61 6c 75 65 et <name> <value
37a0: 3e 20 3c 66 6f 72 6d 61 74 3e 20 2e 2e 2e 29 7d > <format> ...)}
37b0: 0a 5c 73 75 62 73 75 62 73 65 63 74 69 6f 6e 2a .\subsubsection*
37c0: 7b 28 66 6d 74 2d 62 69 6e 64 20 3c 6e 61 6d 65 {(fmt-bind <name
37d0: 3e 20 3c 76 61 6c 75 65 3e 20 3c 66 6f 72 6d 61 > <value> <forma
37e0: 74 3e 20 2e 2e 2e 29 7d 0a 0a 5c 71 7b 66 6d 74 t> ...)}..\q{fmt
37f0: 2d 6c 65 74 7d 20 73 65 74 73 20 74 68 65 20 6e -let} sets the n
3800: 61 6d 65 20 66 6f 72 20 74 68 65 20 64 75 72 61 ame for the dura
3810: 74 69 6f 6e 20 6f 66 20 74 68 65 20 5c 71 7b 3c tion of the \q{<
3820: 66 6f 72 6d 61 74 3e 7d 73 2c 20 61 6e 64 0a 72 format>}s, and.r
3830: 65 73 74 6f 72 65 73 20 69 74 20 6f 6e 20 72 65 estores it on re
3840: 74 75 72 6e 2e 20 20 5c 71 7b 66 6d 74 2d 62 69 turn. \q{fmt-bi
3850: 6e 64 7d 20 73 65 74 73 20 69 74 20 77 69 74 68 nd} sets it with
3860: 6f 75 74 20 72 65 73 74 6f 72 69 6e 67 20 69 74 out restoring it
3870: 2e 0a 0a 41 20 63 6f 6e 76 65 6e 69 65 6e 63 65 ...A convenience
3880: 20 63 6f 6e 74 72 6f 6c 20 73 74 72 75 63 74 75 control structu
3890: 72 65 20 63 61 6e 20 62 65 20 75 73 65 66 75 6c re can be useful
38a0: 20 69 6e 20 63 6f 6d 62 69 6e 61 74 69 6f 6e 20 in combination
38b0: 77 69 74 68 0a 74 68 65 73 65 20 73 74 61 74 65 with.these state
38c0: 73 3a 0a 0a 5c 73 75 62 73 75 62 73 65 63 74 69 s:..\subsubsecti
38d0: 6f 6e 2a 7b 28 66 6d 74 2d 69 66 20 3c 70 72 65 on*{(fmt-if <pre
38e0: 64 3e 20 3c 70 61 73 73 3e 20 5b 3c 66 61 69 6c d> <pass> [<fail
38f0: 3e 5d 29 7d 0a 0a 5c 71 7b 3c 70 72 65 64 3e 7d >])}..\q{<pred>}
3900: 20 74 61 6b 65 73 20 6f 6e 65 20 61 72 67 75 6d takes one argum
3910: 65 6e 74 20 28 74 68 65 20 66 6f 72 6d 61 74 20 ent (the format
3920: 73 74 61 74 65 29 20 61 6e 64 20 72 65 74 75 72 state) and retur
3930: 6e 73 20 61 20 62 6f 6f 6c 65 61 6e 0a 72 65 73 ns a boolean.res
3940: 75 6c 74 2e 20 20 49 66 20 74 72 75 65 2c 20 74 ult. If true, t
3950: 68 65 20 5c 71 7b 3c 70 61 73 73 3e 7d 20 66 6f he \q{<pass>} fo
3960: 72 6d 61 74 20 69 73 20 61 70 70 6c 69 65 64 20 rmat is applied
3970: 74 6f 20 74 68 65 20 73 74 61 74 65 2c 0a 6f 74 to the state,.ot
3980: 68 65 72 77 69 73 65 20 5c 71 7b 3c 66 61 69 6c herwise \q{<fail
3990: 3e 7d 20 28 64 65 66 61 75 6c 74 69 6e 67 20 74 >} (defaulting t
39a0: 6f 20 74 68 65 20 69 64 65 6e 74 69 74 79 29 20 o the identity)
39b0: 69 73 20 61 70 70 6c 69 65 64 2e 0a 0a 4d 61 6e is applied...Man
39c0: 79 20 6f 66 20 74 68 65 20 70 72 65 76 69 6f 75 y of the previou
39d0: 73 6c 79 20 6d 65 6e 74 69 6f 6e 65 64 20 63 6f sly mentioned co
39e0: 6d 62 69 6e 61 74 6f 72 73 20 68 61 76 65 20 62 mbinators have b
39f0: 65 68 61 76 69 6f 72 20 77 68 69 63 68 20 63 61 ehavior which ca
3a00: 6e 0a 62 65 20 61 6c 74 65 72 65 64 20 77 69 74 n.be altered wit
3a10: 68 20 73 74 61 74 65 20 76 61 72 69 61 62 6c 65 h state variable
3a20: 73 2e 20 20 41 6c 74 68 6f 75 67 68 20 5c 71 7b s. Although \q{
3a30: 66 6d 74 2d 6c 65 74 7d 20 61 6e 64 20 5c 71 7b fmt-let} and \q{
3a40: 66 6d 74 2d 62 69 6e 64 7d 0a 63 6f 75 6c 64 20 fmt-bind}.could
3a50: 62 65 20 75 73 65 64 2c 20 74 68 65 73 65 20 63 be used, these c
3a60: 6f 6d 6d 6f 6e 20 76 61 72 69 61 62 6c 65 73 20 ommon variables
3a70: 68 61 76 65 20 73 68 6f 72 74 63 75 74 73 3a 0a have shortcuts:.
3a80: 0a 5c 73 75 62 73 75 62 73 65 63 74 69 6f 6e 2a .\subsubsection*
3a90: 7b 28 72 61 64 69 78 20 3c 6b 3e 20 3c 66 6f 72 {(radix <k> <for
3aa0: 6d 61 74 3e 20 2e 2e 2e 29 7d 0a 5c 73 75 62 73 mat> ...)}.\subs
3ab0: 75 62 73 65 63 74 69 6f 6e 2a 7b 28 66 69 78 20 ubsection*{(fix
3ac0: 3c 6b 3e 20 3c 66 6f 72 6d 61 74 3e 20 2e 2e 2e <k> <format> ...
3ad0: 29 7d 0a 0a 54 68 65 73 65 20 61 6c 74 65 72 20 )}..These alter
3ae0: 74 68 65 20 72 61 64 69 78 20 61 6e 64 20 66 69 the radix and fi
3af0: 78 65 64 20 70 6f 69 6e 74 20 70 72 65 63 69 73 xed point precis
3b00: 69 6f 6e 20 6f 66 20 6e 75 6d 62 65 72 73 20 6f ion of numbers o
3b10: 75 74 70 75 74 20 77 69 74 68 0a 5c 71 7b 64 73 utput with.\q{ds
3b20: 70 7d 2c 20 5c 71 7b 77 72 74 7d 2c 20 5c 71 7b p}, \q{wrt}, \q{
3b30: 70 72 65 74 74 79 7d 20 6f 72 20 5c 71 7b 6e 75 pretty} or \q{nu
3b40: 6d 7d 2e 20 20 54 68 65 73 65 20 73 65 74 74 69 m}. These setti
3b50: 6e 67 73 20 61 70 70 6c 79 0a 72 65 63 75 72 73 ngs apply.recurs
3b60: 69 76 65 6c 79 20 74 6f 20 61 6c 6c 20 6f 75 74 ively to all out
3b70: 70 75 74 20 64 61 74 61 20 73 74 72 75 63 74 75 put data structu
3b80: 72 65 73 2c 20 73 6f 20 74 68 61 74 0a 0a 20 20 res, so that..
3b90: 5c 71 7b 28 66 6d 74 20 23 66 20 28 72 61 64 69 \q{(fmt #f (radi
3ba0: 78 20 31 36 20 27 28 37 30 20 38 30 20 39 30 29 x 16 '(70 80 90)
3bb0: 29 29 7d 0a 0a 77 69 6c 6c 20 72 65 74 75 72 6e ))}..will return
3bc0: 20 74 68 65 20 73 74 72 69 6e 67 20 5c 71 7b 22 the string \q{"
3bd0: 28 23 78 34 36 20 23 78 35 30 20 23 78 35 61 29 (#x46 #x50 #x5a)
3be0: 22 7d 2e 20 20 4e 6f 74 65 20 74 68 61 74 20 72 "}. Note that r
3bf0: 65 61 64 2f 77 72 69 74 65 0a 69 6e 76 61 72 69 ead/write.invari
3c00: 61 6e 63 65 20 69 73 20 65 73 73 65 6e 74 69 61 ance is essentia
3c10: 6c 2c 20 73 6f 20 66 6f 72 20 5c 71 7b 64 73 70 l, so for \q{dsp
3c20: 7d 2c 20 5c 71 7b 77 72 74 7d 20 61 6e 64 20 5c }, \q{wrt} and \
3c30: 71 7b 70 72 65 74 74 79 7d 20 74 68 65 0a 72 61 q{pretty} the.ra
3c40: 64 69 78 20 70 72 65 66 69 78 20 69 73 20 61 6c dix prefix is al
3c50: 77 61 79 73 20 69 6e 63 6c 75 64 65 64 20 77 68 ways included wh
3c60: 65 6e 20 6e 6f 74 20 64 65 63 69 6d 61 6c 2e 20 en not decimal.
3c70: 20 55 73 65 20 5c 71 7b 6e 75 6d 7d 20 69 66 20 Use \q{num} if
3c80: 79 6f 75 0a 77 61 6e 74 20 74 6f 20 66 6f 72 6d you.want to form
3c90: 61 74 20 6e 75 6d 62 65 72 73 20 69 6e 20 61 6c at numbers in al
3ca0: 74 65 72 6e 61 74 65 20 62 61 73 65 73 20 77 69 ternate bases wi
3cb0: 74 68 6f 75 74 20 74 68 69 73 20 70 72 65 66 69 thout this prefi
3cc0: 78 2e 20 20 46 6f 72 0a 65 78 61 6d 70 6c 65 2c x. For.example,
3cd0: 0a 0a 20 20 5c 71 7b 28 66 6d 74 20 23 66 20 28 .. \q{(fmt #f (
3ce0: 72 61 64 69 78 20 31 36 20 22 28 22 20 28 66 6d radix 16 "(" (fm
3cf0: 74 2d 6a 6f 69 6e 20 6e 75 6d 20 27 28 37 30 20 t-join num '(70
3d00: 38 30 20 39 30 29 20 22 20 22 29 20 22 29 22 29 80 90) " ") ")")
3d10: 29 7d 0a 0a 77 6f 75 6c 64 20 72 65 74 75 72 6e )}..would return
3d20: 20 5c 71 7b 22 28 34 36 20 35 30 20 35 61 29 22 \q{"(46 50 5a)"
3d30: 7d 2c 20 74 68 65 20 73 61 6d 65 20 6f 75 74 70 }, the same outp
3d40: 75 74 20 61 73 20 61 62 6f 76 65 20 77 69 74 68 ut as above with
3d50: 6f 75 74 20 74 68 65 0a 22 23 78 22 20 72 61 64 out the."#x" rad
3d60: 69 78 20 70 72 65 66 69 78 2e 0a 0a 4e 6f 74 65 ix prefix...Note
3d70: 20 74 68 61 74 20 66 69 78 65 64 20 70 6f 69 6e that fixed poin
3d80: 74 20 66 6f 72 6d 61 74 74 69 6e 67 20 73 75 70 t formatting sup
3d90: 70 6f 72 74 73 20 61 72 62 69 74 72 61 72 79 20 ports arbitrary
3da0: 70 72 65 63 69 73 69 6f 6e 20 69 6e 0a 69 6d 70 precision in.imp
3db0: 6c 65 6d 65 6e 74 61 74 69 6f 6e 73 20 77 69 74 lementations wit
3dc0: 68 20 65 78 61 63 74 20 6e 6f 6e 2d 69 6e 74 65 h exact non-inte
3dd0: 67 72 61 6c 20 72 61 74 69 6f 6e 61 6c 73 2e 20 gral rationals.
3de0: 20 57 68 65 6e 20 74 72 79 69 6e 67 20 74 6f 0a When trying to.
3df0: 70 72 69 6e 74 20 69 6e 65 78 61 63 74 20 6e 75 print inexact nu
3e00: 6d 62 65 72 73 20 6d 6f 72 65 20 74 68 61 6e 20 mbers more than
3e10: 74 68 65 20 6d 61 63 68 69 6e 65 20 70 72 65 63 the machine prec
3e20: 69 73 69 6f 6e 20 79 6f 75 20 77 69 6c 6c 0a 74 ision you will.t
3e30: 79 70 69 63 61 6c 6c 79 20 67 65 74 20 72 65 73 ypically get res
3e40: 75 6c 74 73 20 6c 69 6b 65 0a 0a 20 20 5c 71 7b ults like.. \q{
3e50: 28 66 6d 74 20 23 66 20 28 66 69 78 20 33 30 20 (fmt #f (fix 30
3e60: 23 69 32 2f 33 29 29 7d 0a 0a 20 20 5c 71 7b 3d #i2/3))}.. \q{=
3e70: 3e 20 22 30 2e 36 36 36 36 36 36 36 36 36 36 36 > "0.66666666666
3e80: 36 36 36 36 36 30 30 30 30 30 30 30 30 30 30 30 6666600000000000
3e90: 30 30 30 22 7d 0a 0a 62 75 74 20 77 69 74 68 20 000"}..but with
3ea0: 61 6e 20 65 78 61 63 74 20 72 61 74 69 6f 6e 61 an exact rationa
3eb0: 6c 20 69 74 20 77 69 6c 6c 20 67 69 76 65 20 79 l it will give y
3ec0: 6f 75 20 61 73 20 6d 61 6e 79 20 64 69 67 69 74 ou as many digit
3ed0: 73 20 61 73 20 79 6f 75 0a 72 65 71 75 65 73 74 s as you.request
3ee0: 3a 0a 0a 20 20 5c 71 7b 28 66 6d 74 20 23 66 20 :.. \q{(fmt #f
3ef0: 28 66 69 78 20 33 30 20 32 2f 33 29 29 7d 0a 0a (fix 30 2/3))}..
3f00: 20 20 5c 71 7b 3d 3e 20 22 30 2e 36 36 36 36 36 \q{=> "0.66666
3f10: 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 6666666666666666
3f20: 36 36 36 36 36 36 36 36 37 22 7d 0a 0a 5c 73 75 666666667"}..\su
3f30: 62 73 75 62 73 65 63 74 69 6f 6e 2a 7b 28 64 65 bsubsection*{(de
3f40: 63 69 6d 61 6c 2d 61 6c 69 67 6e 20 3c 6b 3e 20 cimal-align <k>
3f50: 3c 66 6f 72 6d 61 74 3e 20 2e 2e 2e 29 7d 0a 0a <format> ...)}..
3f60: 53 70 65 63 69 66 69 65 73 20 61 6e 20 61 6c 69 Specifies an ali
3f70: 67 6e 6d 65 6e 74 20 66 6f 72 20 74 68 65 20 64 gnment for the d
3f80: 65 63 69 6d 61 6c 20 70 6c 61 63 65 20 77 68 65 ecimal place whe
3f90: 6e 20 66 6f 72 6d 61 74 74 69 6e 67 20 6e 75 6d n formatting num
3fa0: 62 65 72 73 2c 0a 75 73 65 66 75 6c 20 66 6f 72 bers,.useful for
3fb0: 20 6f 75 74 70 75 74 74 69 6e 67 20 74 61 62 6c outputting tabl
3fc0: 65 73 20 6f 66 20 6e 75 6d 62 65 72 73 2e 0a 0a es of numbers...
3fd0: 5c 71 7b 0a 20 20 28 64 65 66 69 6e 65 20 28 70 \q{. (define (p
3fe0: 72 69 6e 74 2d 61 6e 67 6c 65 73 20 78 29 0a 20 rint-angles x).
3ff0: 20 20 20 20 28 66 6d 74 2d 6a 6f 69 6e 20 6e 75 (fmt-join nu
4000: 6d 20 28 6c 69 73 74 20 78 20 28 73 69 6e 20 78 m (list x (sin x
4010: 29 20 28 63 6f 73 20 78 29 20 28 74 61 6e 20 78 ) (cos x) (tan x
4020: 29 29 20 22 20 22 29 29 0a 0a 20 20 28 66 6d 74 )) " ")).. (fmt
4030: 20 23 74 20 28 64 65 63 69 6d 61 6c 2d 61 6c 69 #t (decimal-ali
4040: 67 6e 20 35 20 28 66 69 78 20 33 20 28 66 6d 74 gn 5 (fix 3 (fmt
4050: 2d 6a 6f 69 6e 2f 73 75 66 66 69 78 20 70 72 69 -join/suffix pri
4060: 6e 74 2d 61 6e 67 6c 65 73 20 28 69 6f 74 61 20 nt-angles (iota
4070: 35 29 20 6e 6c 29 29 29 29 0a 7d 0a 0a 77 6f 75 5) nl)))).}..wou
4080: 6c 64 20 6f 75 74 70 75 74 0a 0a 5c 70 7b 0a 20 ld output..\p{.
4090: 20 20 30 2e 30 30 30 20 20 20 20 30 2e 30 30 30 0.000 0.000
40a0: 20 20 20 20 31 2e 30 30 30 20 20 20 20 30 2e 30 1.000 0.0
40b0: 30 30 0a 20 20 20 31 2e 30 30 30 20 20 20 20 30 00. 1.000 0
40c0: 2e 38 34 32 20 20 20 20 30 2e 35 34 30 20 20 20 .842 0.540
40d0: 20 31 2e 35 35 37 0a 20 20 20 32 2e 30 30 30 20 1.557. 2.000
40e0: 20 20 20 30 2e 39 30 39 20 20 20 2d 30 2e 34 31 0.909 -0.41
40f0: 36 20 20 20 2d 32 2e 31 38 35 0a 20 20 20 33 2e 6 -2.185. 3.
4100: 30 30 30 20 20 20 20 30 2e 31 34 31 20 20 20 2d 000 0.141 -
4110: 30 2e 39 39 30 20 20 20 2d 30 2e 31 34 32 0a 20 0.990 -0.142.
4120: 20 20 34 2e 30 30 30 20 20 20 2d 30 2e 37 35 37 4.000 -0.757
4130: 20 20 20 2d 30 2e 36 35 34 20 20 20 20 31 2e 31 -0.654 1.1
4140: 35 38 0a 7d 0a 0a 5c 73 75 62 73 75 62 73 65 63 58.}..\subsubsec
4150: 74 69 6f 6e 2a 7b 28 63 6f 6d 6d 61 2d 63 68 61 tion*{(comma-cha
4160: 72 20 3c 6b 3e 20 3c 66 6f 72 6d 61 74 3e 20 2e r <k> <format> .
4170: 2e 2e 29 7d 0a 5c 73 75 62 73 75 62 73 65 63 74 ..)}.\subsubsect
4180: 69 6f 6e 2a 7b 28 64 65 63 69 6d 61 6c 2d 63 68 ion*{(decimal-ch
4190: 61 72 20 3c 6b 3e 20 3c 66 6f 72 6d 61 74 3e 20 ar <k> <format>
41a0: 2e 2e 2e 29 7d 0a 0a 5c 71 7b 63 6f 6d 6d 61 2d ...)}..\q{comma-
41b0: 63 68 61 72 7d 20 61 6e 64 20 5c 71 7b 64 65 63 char} and \q{dec
41c0: 69 6d 61 6c 2d 63 68 61 72 7d 20 73 65 74 20 74 imal-char} set t
41d0: 68 65 20 64 65 66 61 75 6c 74 73 20 66 6f 72 20 he defaults for
41e0: 6e 75 6d 62 65 72 0a 66 6f 72 6d 61 74 74 69 6e number.formattin
41f0: 67 2e 0a 0a 5c 73 75 62 73 75 62 73 65 63 74 69 g...\subsubsecti
4200: 6f 6e 2a 7b 28 70 61 64 2d 63 68 61 72 20 3c 6b on*{(pad-char <k
4210: 3e 20 3c 66 6f 72 6d 61 74 3e 20 2e 2e 2e 29 7d > <format> ...)}
4220: 0a 0a 54 68 65 20 5c 71 7b 70 61 64 2d 63 68 61 ..The \q{pad-cha
4230: 72 7d 20 73 65 74 73 20 74 68 65 20 63 68 61 72 r} sets the char
4240: 61 63 74 65 72 20 75 73 65 64 20 62 79 20 5c 71 acter used by \q
4250: 7b 73 70 61 63 65 2d 74 6f 7d 2c 20 5c 71 7b 74 {space-to}, \q{t
4260: 61 62 2d 74 6f 7d 2c 0a 5c 71 7b 70 61 64 2f 2a ab-to},.\q{pad/*
4270: 7d 2c 20 61 6e 64 20 5c 71 7b 66 69 74 2f 2a 7d }, and \q{fit/*}
4280: 2c 20 61 6e 64 20 64 65 66 61 75 6c 74 73 20 74 , and defaults t
4290: 6f 20 5c 71 7b 23 5c 73 70 61 63 65 7d 2e 0a 0a o \q{#\space}...
42a0: 5c 71 7b 0a 20 20 28 64 65 66 69 6e 65 20 28 70 \q{. (define (p
42b0: 72 69 6e 74 2d 74 61 62 6c 65 2d 6f 66 2d 63 6f rint-table-of-co
42c0: 6e 74 65 6e 74 73 20 61 6c 69 73 74 29 0a 20 20 ntents alist).
42d0: 20 20 28 64 65 66 69 6e 65 20 28 70 72 69 6e 74 (define (print
42e0: 2d 6c 69 6e 65 20 78 29 0a 20 20 20 20 20 20 28 -line x). (
42f0: 63 61 74 20 28 63 61 72 20 78 29 20 28 73 70 61 cat (car x) (spa
4300: 63 65 2d 74 6f 20 37 32 29 20 28 70 61 64 2f 6c ce-to 72) (pad/l
4310: 65 66 74 20 33 20 28 63 64 72 20 78 29 29 29 29 eft 3 (cdr x))))
4320: 0a 20 20 20 20 28 66 6d 74 20 23 74 20 28 70 61 . (fmt #t (pa
4330: 64 2d 63 68 61 72 20 23 5c 2e 20 28 66 6d 74 2d d-char #\. (fmt-
4340: 6a 6f 69 6e 2f 73 75 66 66 69 78 20 70 72 69 6e join/suffix prin
4350: 74 2d 6c 69 6e 65 20 61 6c 69 73 74 20 6e 6c 29 t-line alist nl)
4360: 29 29 29 0a 0a 20 20 28 70 72 69 6e 74 2d 74 61 ))).. (print-ta
4370: 62 6c 65 2d 6f 66 2d 63 6f 6e 74 65 6e 74 73 0a ble-of-contents.
4380: 20 20 20 27 28 28 22 41 6e 20 55 6e 65 78 70 65 '(("An Unexpe
4390: 63 74 65 64 20 50 61 72 74 79 22 20 2e 20 32 39 cted Party" . 29
43a0: 29 0a 20 20 20 20 20 28 22 52 6f 61 73 74 20 4d ). ("Roast M
43b0: 75 74 74 6f 6e 22 20 2e 20 36 30 29 0a 20 20 20 utton" . 60).
43c0: 20 20 28 22 41 20 53 68 6f 72 74 20 52 65 73 74 ("A Short Rest
43d0: 22 20 2e 20 38 37 29 0a 20 20 20 20 20 28 22 4f " . 87). ("O
43e0: 76 65 72 20 48 69 6c 6c 20 61 6e 64 20 55 6e 64 ver Hill and Und
43f0: 65 72 20 48 69 6c 6c 22 20 2e 20 31 30 30 29 0a er Hill" . 100).
4400: 20 20 20 20 20 28 22 52 69 64 64 6c 65 73 20 69 ("Riddles i
4410: 6e 20 74 68 65 20 44 61 72 6b 22 20 2e 20 31 31 n the Dark" . 11
4420: 35 29 29 29 0a 7d 0a 0a 77 6f 75 6c 64 20 6f 75 5))).}..would ou
4430: 74 70 75 74 0a 0a 5c 70 7b 0a 20 20 41 6e 20 55 tput..\p{. An U
4440: 6e 65 78 70 65 63 74 65 64 20 50 61 72 74 79 2e nexpected Party.
4450: 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ................
4460: 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ................
4470: 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ................
4480: 2e 2e 2e 2e 32 39 0a 20 20 52 6f 61 73 74 20 4d ....29. Roast M
4490: 75 74 74 6f 6e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e utton...........
44a0: 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ................
44b0: 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ................
44c0: 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ................
44d0: 2e 36 30 0a 20 20 41 20 53 68 6f 72 74 20 52 65 .60. A Short Re
44e0: 73 74 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e st..............
44f0: 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ................
4500: 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ................
4510: 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 38 37 ..............87
4520: 0a 20 20 4f 76 65 72 20 48 69 6c 6c 20 61 6e 64 . Over Hill and
4530: 20 55 6e 64 65 72 20 48 69 6c 6c 2e 2e 2e 2e 2e Under Hill.....
4540: 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ................
4550: 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ................
4560: 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 31 30 30 0a 20 20 ..........100.
4570: 52 69 64 64 6c 65 73 20 69 6e 20 74 68 65 20 44 Riddles in the D
4580: 61 72 6b 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ark.............
4590: 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ................
45a0: 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e ................
45b0: 2e 2e 2e 2e 2e 2e 2e 31 31 35 0a 7d 0a 0a 5c 73 .......115.}..\s
45c0: 75 62 73 75 62 73 65 63 74 69 6f 6e 2a 7b 28 65 ubsubsection*{(e
45d0: 6c 6c 69 70 73 65 20 3c 65 6c 6c 3e 20 3c 66 6f llipse <ell> <fo
45e0: 72 6d 61 74 3e 20 2e 2e 2e 29 7d 0a 0a 53 65 74 rmat> ...)}..Set
45f0: 73 20 74 68 65 20 74 72 75 6e 63 61 74 69 6f 6e s the truncation
4600: 20 65 6c 6c 69 70 73 65 20 74 6f 20 5c 71 7b 3c ellipse to \q{<
4610: 65 6c 6c 3e 7d 2c 20 77 6f 75 6c 64 20 73 68 6f ell>}, would sho
4620: 75 6c 64 20 62 65 20 61 20 73 74 72 69 6e 67 20 uld be a string
4630: 6f 72 0a 63 68 61 72 61 63 74 65 72 2e 0a 0a 5c or.character...\
4640: 73 75 62 73 75 62 73 65 63 74 69 6f 6e 2a 7b 28 subsubsection*{(
4650: 77 69 74 68 2d 77 69 64 74 68 20 3c 77 69 64 74 with-width <widt
4660: 68 3e 20 3c 66 6f 72 6d 61 74 3e 20 2e 2e 2e 29 h> <format> ...)
4670: 7d 0a 0a 53 65 74 73 20 74 68 65 20 6d 61 78 69 }..Sets the maxi
4680: 6d 75 6d 20 63 6f 6c 75 6d 6e 20 77 69 64 74 68 mum column width
4690: 20 75 73 65 64 20 62 79 20 73 6f 6d 65 20 66 6f used by some fo
46a0: 72 6d 61 74 74 65 72 73 2e 20 20 54 68 65 20 64 rmatters. The d
46b0: 65 66 61 75 6c 74 0a 69 73 20 37 38 2e 0a 0a 0a efault.is 78....
46c0: 5c 73 75 62 73 65 63 74 69 6f 6e 7b 43 6f 6c 75 \subsection{Colu
46d0: 6d 6e 61 72 20 46 6f 72 6d 61 74 74 69 6e 67 7d mnar Formatting}
46e0: 0a 0a 41 6c 74 68 6f 75 67 68 20 5c 71 7b 74 61 ..Although \q{ta
46f0: 62 2d 74 6f 7d 2c 20 5c 71 7b 73 70 61 63 65 2d b-to}, \q{space-
4700: 74 6f 7d 20 61 6e 64 20 70 61 64 64 69 6e 67 20 to} and padding
4710: 63 61 6e 20 62 65 20 75 73 65 64 20 74 6f 20 6d can be used to m
4720: 61 6e 75 61 6c 6c 79 0a 61 6c 69 67 6e 20 63 6f anually.align co
4730: 6c 75 6d 6e 73 20 74 6f 20 70 72 6f 64 75 63 65 lumns to produce
4740: 20 74 61 62 6c 65 2d 6c 69 6b 65 20 6f 75 74 70 table-like outp
4750: 75 74 2c 20 74 68 65 73 65 20 63 61 6e 20 62 65 ut, these can be
4760: 20 61 77 6b 77 61 72 64 20 74 6f 0a 75 73 65 2e awkward to.use.
4770: 20 20 54 68 65 20 6f 70 74 69 6f 6e 61 6c 20 65 The optional e
4780: 78 74 65 6e 73 69 6f 6e 73 20 69 6e 20 74 68 69 xtensions in thi
4790: 73 20 73 65 63 74 69 6f 6e 20 6d 61 6b 65 20 74 s section make t
47a0: 68 69 73 20 65 61 73 69 65 72 2e 0a 0a 5c 73 75 his easier...\su
47b0: 62 73 75 62 73 65 63 74 69 6f 6e 2a 7b 28 63 6f bsubsection*{(co
47c0: 6c 75 6d 6e 61 72 20 3c 63 6f 6c 75 6d 6e 3e 20 lumnar <column>
47d0: 2e 2e 2e 29 7d 0a 0a 46 6f 72 6d 61 74 73 20 65 ...)}..Formats e
47e0: 61 63 68 20 5c 71 7b 3c 63 6f 6c 75 6d 6e 3e 7d ach \q{<column>}
47f0: 20 73 69 64 65 2d 62 79 2d 73 69 64 65 2c 20 69 side-by-side, i
4800: 2e 65 2e 20 61 73 20 74 68 6f 75 67 68 20 65 61 .e. as though ea
4810: 63 68 20 77 65 72 65 0a 66 6f 72 6d 61 74 74 65 ch were.formatte
4820: 64 20 73 65 70 61 72 61 74 65 6c 79 20 61 6e 64 d separately and
4830: 20 74 68 65 6e 20 74 68 65 20 69 6e 64 69 76 69 then the indivi
4840: 64 75 61 6c 20 6c 69 6e 65 73 20 63 6f 6e 63 61 dual lines conca
4850: 74 65 6e 61 74 65 64 0a 74 6f 67 65 74 68 65 72 tenated.together
4860: 2e 20 20 54 68 65 20 63 75 72 72 65 6e 74 20 63 . The current c
4870: 6f 6c 75 6d 6e 20 77 69 64 74 68 20 69 73 20 64 olumn width is d
4880: 69 76 69 64 65 64 20 65 76 65 6e 6c 79 20 61 6d ivided evenly am
4890: 6f 6e 67 20 74 68 65 0a 63 6f 6c 75 6d 6e 73 2c ong the.columns,
48a0: 20 61 6e 64 20 61 6c 6c 20 62 75 74 20 74 68 65 and all but the
48b0: 20 6c 61 73 74 20 63 6f 6c 75 6d 6e 20 61 72 65 last column are
48c0: 20 72 69 67 68 74 2d 70 61 64 64 65 64 2e 20 20 right-padded.
48d0: 46 6f 72 20 65 78 61 6d 70 6c 65 0a 0a 20 20 5c For example.. \
48e0: 71 7b 28 66 6d 74 20 23 74 20 28 63 6f 6c 75 6d q{(fmt #t (colum
48f0: 6e 61 72 20 28 64 73 70 20 22 61 62 63 5c 5c 6e nar (dsp "abc\\n
4900: 64 65 66 5c 5c 6e 22 29 20 28 64 73 70 20 22 31 def\\n") (dsp "1
4910: 32 33 5c 5c 6e 34 35 36 5c 5c 6e 22 29 29 29 7d 23\\n456\\n")))}
4920: 0a 0a 6f 75 74 70 75 74 73 0a 0a 5c 70 7b 0a 20 ..outputs..\p{.
4930: 20 20 20 20 61 62 63 20 20 20 20 20 31 32 33 0a abc 123.
4940: 20 20 20 20 20 64 65 66 20 20 20 20 20 34 35 36 def 456
4950: 0a 7d 0a 0a 61 73 73 75 6d 69 6e 67 20 61 20 31 .}..assuming a 1
4960: 36 2d 63 68 61 72 20 77 69 64 74 68 20 28 74 68 6-char width (th
4970: 65 20 6c 65 66 74 20 73 69 64 65 20 67 65 74 73 e left side gets
4980: 20 68 61 6c 66 20 74 68 65 20 77 69 64 74 68 2c half the width,
4990: 20 6f 72 20 38 0a 73 70 61 63 65 73 2c 20 61 6e or 8.spaces, an
49a0: 64 20 69 73 20 6c 65 66 74 20 61 6c 69 67 6e 65 d is left aligne
49b0: 64 29 2e 20 20 4e 6f 74 65 20 74 68 61 74 20 77 d). Note that w
49c0: 65 20 65 78 70 6c 69 63 69 74 6c 79 20 75 73 65 e explicitly use
49d0: 20 44 53 50 20 69 6e 73 74 65 61 64 0a 6f 66 20 DSP instead.of
49e0: 74 68 65 20 73 74 72 69 6e 67 73 20 64 69 72 65 the strings dire
49f0: 63 74 6c 79 2e 20 20 54 68 69 73 20 69 73 20 62 ctly. This is b
4a00: 65 63 61 75 73 65 20 5c 71 7b 63 6f 6c 75 6d 6e ecause \q{column
4a10: 61 72 7d 20 74 72 65 61 74 73 20 72 61 77 0a 73 ar} treats raw.s
4a20: 74 72 69 6e 67 73 20 61 73 20 6c 69 74 65 72 61 trings as litera
4a30: 6c 73 20 69 6e 73 65 72 74 65 64 20 69 6e 74 6f ls inserted into
4a40: 20 74 68 65 20 67 69 76 65 6e 20 6c 6f 63 61 74 the given locat
4a50: 69 6f 6e 20 6f 6e 20 65 76 65 72 79 20 6c 69 6e ion on every lin
4a60: 65 2c 20 74 6f 0a 62 65 20 75 73 65 64 20 61 73 e, to.be used as
4a70: 20 62 6f 72 64 65 72 73 2c 20 66 6f 72 20 65 78 borders, for ex
4a80: 61 6d 70 6c 65 3a 0a 0a 5c 71 7b 0a 20 20 28 66 ample:..\q{. (f
4a90: 6d 74 20 23 74 20 28 63 6f 6c 75 6d 6e 61 72 20 mt #t (columnar
4aa0: 22 2f 2a 20 22 20 28 64 73 70 20 22 61 62 63 5c "/* " (dsp "abc\
4ab0: 5c 6e 64 65 66 5c 5c 6e 22 29 0a 20 20 20 20 20 \ndef\\n").
4ac0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 22 "
4ad0: 20 7c 20 22 20 28 64 73 70 20 22 31 32 33 5c 5c | " (dsp "123\\
4ae0: 6e 34 35 36 5c 5c 6e 22 29 0a 20 20 20 20 20 20 n456\\n").
4af0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 22 20 "
4b00: 2a 2f 22 29 29 0a 7d 0a 0a 77 6f 75 6c 64 20 6f */")).}..would o
4b10: 75 74 70 75 74 0a 0a 5c 70 7b 0a 20 20 2f 2a 20 utput..\p{. /*
4b20: 61 62 63 20 7c 20 31 32 33 20 2a 2f 0a 20 20 2f abc | 123 */. /
4b30: 2a 20 64 65 66 20 7c 20 34 35 36 20 2a 2f 0a 7d * def | 456 */.}
4b40: 0a 0a 59 6f 75 20 6d 61 79 20 61 6c 73 6f 20 70 ..You may also p
4b50: 72 65 66 69 78 20 61 6e 79 20 63 6f 6c 75 6d 6e refix any column
4b60: 20 77 69 74 68 20 61 6e 79 20 6f 66 20 74 68 65 with any of the
4b70: 20 73 79 6d 62 6f 6c 73 20 5c 71 7b 27 6c 65 66 symbols \q{'lef
4b80: 74 7d 2c 0a 5c 71 7b 27 72 69 67 68 74 7d 20 6f t},.\q{'right} o
4b90: 72 20 5c 71 7b 27 63 65 6e 74 65 72 7d 20 74 6f r \q{'center} to
4ba0: 20 63 6f 6e 74 72 6f 6c 20 74 68 65 20 6a 75 73 control the jus
4bb0: 74 69 66 69 63 61 74 69 6f 6e 2e 20 20 54 68 65 tification. The
4bc0: 20 73 79 6d 62 6f 6c 0a 5c 71 7b 27 69 6e 66 69 symbol.\q{'infi
4bd0: 6e 69 74 65 7d 20 63 61 6e 20 62 65 20 75 73 65 nite} can be use
4be0: 64 20 74 6f 20 69 6e 64 69 63 61 74 65 20 74 68 d to indicate th
4bf0: 65 20 63 6f 6c 75 6d 6e 20 67 65 6e 65 72 61 74 e column generat
4c00: 65 73 20 61 6e 20 69 6e 66 69 6e 69 74 65 0a 73 es an infinite.s
4c10: 74 72 65 61 6d 20 6f 66 20 6f 75 74 70 75 74 2e tream of output.
4c20: 0a 0a 59 6f 75 20 63 61 6e 20 66 75 72 74 68 65 ..You can furthe
4c30: 72 20 70 72 65 66 69 78 20 61 6e 79 20 63 6f 6c r prefix any col
4c40: 75 6d 6e 20 77 69 74 68 20 61 20 77 69 64 74 68 umn with a width
4c50: 20 6d 6f 64 69 66 69 65 72 2e 20 20 41 6e 79 0a modifier. Any.
4c60: 70 6f 73 69 74 69 76 65 20 69 6e 74 65 67 65 72 positive integer
4c70: 20 69 73 20 74 72 65 61 74 65 64 20 61 73 20 61 is treated as a
4c80: 20 66 69 78 65 64 20 77 69 64 74 68 2c 20 69 67 fixed width, ig
4c90: 6e 6f 72 69 6e 67 20 74 68 65 20 61 76 61 69 6c noring the avail
4ca0: 61 62 6c 65 0a 77 69 64 74 68 2e 20 20 41 6e 79 able.width. Any
4cb0: 20 72 65 61 6c 20 6e 75 6d 62 65 72 20 62 65 74 real number bet
4cc0: 77 65 65 6e 20 30 20 61 6e 64 20 31 20 69 6e 64 ween 0 and 1 ind
4cd0: 69 63 61 74 65 73 20 61 20 66 72 61 63 74 69 6f icates a fractio
4ce0: 6e 20 6f 66 20 74 68 65 0a 61 76 61 69 6c 61 62 n of the.availab
4cf0: 6c 65 20 77 69 64 74 68 20 28 61 66 74 65 72 20 le width (after
4d00: 73 75 62 74 72 61 63 74 69 6e 67 20 6f 75 74 20 subtracting out
4d10: 61 6e 79 20 66 69 78 65 64 20 77 69 64 74 68 73 any fixed widths
4d20: 29 2e 20 20 43 6f 6c 75 6d 6e 73 0a 77 69 74 68 ). Columns.with
4d30: 20 75 6e 73 70 65 63 69 66 69 65 64 20 77 69 64 unspecified wid
4d40: 74 68 20 64 69 76 69 64 65 20 75 70 20 74 68 65 th divide up the
4d50: 20 72 65 6d 61 69 6e 69 6e 67 20 77 69 64 74 68 remaining width
4d60: 20 65 76 65 6e 6c 79 2e 0a 0a 4e 6f 74 65 20 74 evenly...Note t
4d70: 68 61 74 20 5c 71 7b 63 6f 6c 75 6d 6e 61 72 7d hat \q{columnar}
4d80: 20 62 75 69 6c 64 73 20 69 74 73 20 6f 75 74 70 builds its outp
4d90: 75 74 20 69 6e 63 72 65 6d 65 6e 74 61 6c 6c 79 ut incrementally
4da0: 2c 20 69 6e 74 65 72 6c 65 61 76 69 6e 67 0a 63 , interleaving.c
4db0: 61 6c 6c 73 20 74 6f 20 74 68 65 20 67 65 6e 65 alls to the gene
4dc0: 72 61 74 6f 72 73 20 75 6e 74 69 6c 20 65 61 63 rators until eac
4dd0: 68 20 68 61 73 20 70 72 6f 64 75 63 65 64 20 61 h has produced a
4de0: 20 6c 69 6e 65 2c 20 74 68 65 6e 0a 63 6f 6e 63 line, then.conc
4df0: 61 74 65 6e 61 74 69 6e 67 20 74 68 61 74 20 6c atenating that l
4e00: 69 6e 65 20 74 6f 67 65 74 68 65 72 20 61 6e 64 ine together and
4e10: 20 6f 75 74 70 75 74 74 69 6e 67 20 69 74 2e 20 outputting it.
4e20: 20 54 68 69 73 20 69 73 20 69 6d 70 6f 72 74 61 This is importa
4e30: 6e 74 0a 62 65 63 61 75 73 65 20 61 73 20 6e 6f nt.because as no
4e40: 74 65 64 20 61 62 6f 76 65 2c 20 73 6f 6d 65 20 ted above, some
4e50: 63 6f 6c 75 6d 6e 73 20 6d 61 79 20 70 72 6f 64 columns may prod
4e60: 75 63 65 20 61 6e 20 69 6e 66 69 6e 69 74 65 20 uce an infinite
4e70: 73 74 72 65 61 6d 20 6f 66 0a 6f 75 74 70 75 74 stream of.output
4e80: 2c 20 61 6e 64 20 69 6e 20 67 65 6e 65 72 61 6c , and in general
4e90: 20 79 6f 75 20 6d 61 79 20 77 61 6e 74 20 74 6f you may want to
4ea0: 20 66 6f 72 6d 61 74 20 64 61 74 61 20 6c 61 72 format data lar
4eb0: 67 65 72 20 74 68 61 6e 20 63 61 6e 20 66 69 74 ger than can fit
4ec0: 0a 69 6e 74 6f 20 6d 65 6d 6f 72 79 2e 20 20 54 .into memory. T
4ed0: 68 75 73 20 63 6f 6c 75 6d 6e 61 72 20 77 6f 75 hus columnar wou
4ee0: 6c 64 20 62 65 20 73 75 69 74 61 62 6c 65 20 66 ld be suitable f
4ef0: 6f 72 20 6c 69 6e 65 20 6e 75 6d 62 65 72 69 6e or line numberin
4f00: 67 20 61 0a 66 69 6c 65 20 6f 66 20 61 72 62 69 g a.file of arbi
4f10: 74 72 61 72 79 20 73 69 7a 65 2c 20 6f 72 20 69 trary size, or i
4f20: 6d 70 6c 65 6d 65 6e 74 69 6e 67 20 74 68 65 20 mplementing the
4f30: 55 6e 69 78 20 5c 71 7b 79 65 73 28 31 29 7d 20 Unix \q{yes(1)}
4f40: 63 6f 6d 6d 61 6e 64 2c 0a 65 74 63 2e 0a 0a 41 command,.etc...A
4f50: 73 20 61 6e 20 69 6d 70 6c 65 6d 65 6e 74 61 74 s an implementat
4f60: 69 6f 6e 20 64 65 74 61 69 6c 2c 20 5c 71 7b 63 ion detail, \q{c
4f70: 6f 6c 75 6d 6e 61 72 7d 20 75 73 65 73 20 66 69 olumnar} uses fi
4f80: 72 73 74 2d 63 6c 61 73 73 0a 63 6f 6e 74 69 6e rst-class.contin
4f90: 75 61 74 69 6f 6e 73 20 74 6f 20 69 6e 74 65 72 uations to inter
4fa0: 6c 65 61 76 65 20 74 68 65 20 63 6f 6c 75 6d 6e leave the column
4fb0: 20 6f 75 74 70 75 74 2e 20 20 54 68 65 20 63 6f output. The co
4fc0: 72 65 20 5c 71 7b 66 6d 74 7d 0a 69 74 73 65 6c re \q{fmt}.itsel
4fd0: 66 20 68 61 73 20 6e 6f 20 6b 6e 6f 77 6c 65 64 f has no knowled
4fe0: 67 65 20 6f 66 20 6f 72 20 73 70 65 63 69 61 6c ge of or special
4ff0: 20 73 75 70 70 6f 72 74 20 66 6f 72 20 5c 71 7b support for \q{
5000: 63 6f 6c 75 6d 6e 61 72 7d 2c 20 77 68 69 63 68 columnar}, which
5010: 0a 63 6f 75 6c 64 20 63 6f 6d 70 6c 69 63 61 74 .could complicat
5020: 65 20 61 6e 64 20 70 6f 74 65 6e 74 69 61 6c 6c e and potentiall
5030: 79 20 73 6c 6f 77 20 64 6f 77 6e 20 73 69 6d 70 y slow down simp
5040: 6c 65 72 20 5c 71 7b 66 6d 74 7d 20 6f 70 65 72 ler \q{fmt} oper
5050: 61 74 69 6f 6e 73 2e 0a 54 68 69 73 20 69 73 20 ations..This is
5060: 61 20 74 65 73 74 61 6d 65 6e 74 20 74 6f 20 74 a testament to t
5070: 68 65 20 70 6f 77 65 72 20 6f 66 20 5c 71 7b 63 he power of \q{c
5080: 61 6c 6c 2f 63 63 7d 20 2d 20 69 74 20 63 61 6e all/cc} - it can
5090: 20 62 65 20 75 73 65 64 20 74 6f 0a 69 6d 70 6c be used to.impl
50a0: 65 6d 65 6e 74 20 63 6f 72 6f 75 74 69 6e 65 73 ement coroutines
50b0: 20 6f 72 20 61 72 62 69 74 72 61 72 79 20 63 6f or arbitrary co
50c0: 6e 74 72 6f 6c 20 73 74 72 75 63 74 75 72 65 73 ntrol structures
50d0: 20 65 76 65 6e 20 77 68 65 72 65 20 74 68 65 79 even where they
50e0: 0a 77 65 72 65 20 6e 6f 74 20 70 6c 61 6e 6e 65 .were not planne
50f0: 64 20 66 6f 72 2e 0a 0a 5c 73 75 62 73 75 62 73 d for...\subsubs
5100: 65 63 74 69 6f 6e 2a 7b 28 74 61 62 75 6c 61 72 ection*{(tabular
5110: 20 3c 63 6f 6c 75 6d 6e 3e 20 2e 2e 2e 29 7d 0a <column> ...)}.
5120: 0a 45 71 75 69 76 61 6c 65 6e 74 20 74 6f 20 5c .Equivalent to \
5130: 71 7b 63 6f 6c 75 6d 6e 61 72 7d 20 65 78 63 65 q{columnar} exce
5140: 70 74 20 74 68 61 74 20 65 61 63 68 20 63 6f 6c pt that each col
5150: 75 6d 6e 20 69 73 20 70 61 64 64 65 64 20 61 74 umn is padded at
5160: 20 6c 65 61 73 74 0a 74 6f 20 74 68 65 20 6d 69 least.to the mi
5170: 6e 69 6d 75 6d 20 77 69 64 74 68 20 72 65 71 75 nimum width requ
5180: 69 72 65 64 20 6f 6e 20 61 6e 79 20 6f 66 20 69 ired on any of i
5190: 74 73 20 6c 69 6e 65 73 2e 20 20 54 68 75 73 0a ts lines. Thus.
51a0: 0a 20 20 5c 71 7b 28 66 6d 74 20 23 74 20 28 74 . \q{(fmt #t (t
51b0: 61 62 75 6c 61 72 20 22 7c 22 20 28 64 73 70 20 abular "|" (dsp
51c0: 22 61 5c 5c 6e 62 63 5c 5c 6e 64 65 66 5c 5c 6e "a\\nbc\\ndef\\n
51d0: 22 29 20 22 7c 22 20 28 64 73 70 20 22 31 32 33 ") "|" (dsp "123
51e0: 5c 5c 6e 34 35 5c 5c 6e 36 5c 5c 6e 22 29 20 22 \\n45\\n6\\n") "
51f0: 7c 22 29 29 7d 0a 0a 6f 75 74 70 75 74 73 0a 0a |"))}..outputs..
5200: 5c 70 7b 0a 7c 61 20 20 7c 31 32 33 7c 0a 7c 62 \p{.|a |123|.|b
5210: 63 20 7c 34 35 20 7c 0a 7c 64 65 66 7c 36 20 20 c |45 |.|def|6
5220: 7c 0a 7d 0a 0a 54 68 69 73 20 6d 61 6b 65 73 20 |.}..This makes
5230: 69 74 20 65 61 73 69 65 72 20 74 6f 20 67 65 6e it easier to gen
5240: 65 72 61 74 65 20 74 61 62 6c 65 73 20 77 69 74 erate tables wit
5250: 68 6f 75 74 20 6b 6e 6f 77 69 6e 67 20 77 69 64 hout knowing wid
5260: 74 68 73 20 69 6e 0a 61 64 76 61 6e 63 65 2e 20 ths in.advance.
5270: 20 48 6f 77 65 76 65 72 2c 20 62 65 63 61 75 73 However, becaus
5280: 65 20 69 74 20 72 65 71 75 69 72 65 73 20 67 65 e it requires ge
5290: 6e 65 72 61 74 69 6e 67 20 74 68 65 20 65 6e 74 nerating the ent
52a0: 69 72 65 20 6f 75 74 70 75 74 20 69 6e 0a 61 64 ire output in.ad
52b0: 76 61 6e 63 65 20 74 6f 20 64 65 74 65 72 6d 69 vance to determi
52c0: 6e 65 20 74 68 65 20 63 6f 72 72 65 63 74 20 63 ne the correct c
52d0: 6f 6c 75 6d 6e 20 77 69 64 74 68 73 2c 20 5c 71 olumn widths, \q
52e0: 7b 74 61 62 75 6c 61 72 7d 20 63 61 6e 6e 6f 74 {tabular} cannot
52f0: 0a 66 6f 72 6d 61 74 20 61 20 74 61 62 6c 65 20 .format a table
5300: 6c 61 72 67 65 72 20 74 68 61 6e 20 77 6f 75 6c larger than woul
5310: 64 20 66 69 74 20 69 6e 20 6d 65 6d 6f 72 79 2e d fit in memory.
5320: 0a 0a 5c 73 75 62 73 75 62 73 65 63 74 69 6f 6e ..\subsubsection
5330: 2a 7b 28 66 6d 74 2d 63 6f 6c 75 6d 6e 73 20 3c *{(fmt-columns <
5340: 63 6f 6c 75 6d 6e 3e 20 2e 2e 2e 29 7d 0a 0a 54 column> ...)}..T
5350: 68 65 20 6c 6f 77 2d 6c 65 76 65 6c 20 66 6f 72 he low-level for
5360: 6d 61 74 74 65 72 20 6f 6e 20 77 68 69 63 68 20 matter on which
5370: 5c 71 7b 63 6f 6c 75 6d 6e 61 72 7d 20 69 73 20 \q{columnar} is
5380: 62 61 73 65 64 2e 20 20 45 61 63 68 20 5c 71 7b based. Each \q{
5390: 3c 63 6f 6c 75 6d 6e 3e 7d 0a 6d 75 73 74 20 62 <column>}.must b
53a0: 65 20 61 20 6c 69 73 74 20 6f 66 20 32 2d 33 20 e a list of 2-3
53b0: 65 6c 65 6d 65 6e 74 73 3a 0a 0a 20 20 5c 71 7b elements:.. \q{
53c0: 28 3c 6c 69 6e 65 2d 66 6f 72 6d 61 74 74 65 72 (<line-formatter
53d0: 3e 20 3c 6c 69 6e 65 2d 67 65 6e 65 72 61 74 6f > <line-generato
53e0: 72 3e 20 5b 3c 69 6e 66 69 6e 69 74 65 3f 3e 5d r> [<infinite?>]
53f0: 29 7d 0a 0a 77 68 65 72 65 20 5c 71 7b 3c 6c 69 )}..where \q{<li
5400: 6e 65 2d 67 65 6e 65 72 61 74 6f 72 3e 7d 20 69 ne-generator>} i
5410: 73 20 74 68 65 20 63 6f 6c 75 6d 6e 20 67 65 6e s the column gen
5420: 65 72 61 74 6f 72 20 61 73 20 61 62 6f 76 65 2c erator as above,
5430: 20 61 6e 64 20 74 68 65 0a 5c 71 7b 3c 6c 69 6e and the.\q{<lin
5440: 65 2d 66 6f 72 6d 61 74 74 65 72 3e 7d 20 69 73 e-formatter>} is
5450: 20 68 6f 77 20 65 61 63 68 20 6c 69 6e 65 20 69 how each line i
5460: 73 20 66 6f 72 6d 61 74 74 65 64 2e 20 20 52 61 s formatted. Ra
5470: 77 20 63 6f 6e 63 61 74 65 6e 61 74 69 6f 6e 0a w concatenation.
5480: 6f 66 20 65 61 63 68 20 6c 69 6e 65 20 69 73 20 of each line is
5490: 70 65 72 66 6f 72 6d 65 64 2c 20 77 69 74 68 6f performed, witho
54a0: 75 74 20 61 6e 79 20 73 70 61 63 69 6e 67 20 6f ut any spacing o
54b0: 72 20 77 69 64 74 68 20 61 64 6a 75 73 74 6d 65 r width adjustme
54c0: 6e 74 2e 0a 5c 71 7b 3c 69 6e 66 69 6e 69 74 65 nt..\q{<infinite
54d0: 3f 3e 7d 2c 20 69 66 20 74 72 75 65 2c 20 69 6e ?>}, if true, in
54e0: 64 69 63 61 74 65 73 20 74 68 69 73 20 67 65 6e dicates this gen
54f0: 65 72 61 74 6f 72 20 70 72 6f 64 75 63 65 73 20 erator produces
5500: 61 6e 0a 69 6e 66 69 6e 69 74 65 20 6e 75 6d 62 an.infinite numb
5510: 65 72 20 6f 66 20 6c 69 6e 65 73 20 61 6e 64 20 er of lines and
5520: 74 65 72 6d 69 6e 61 74 69 6f 6e 20 73 68 6f 75 termination shou
5530: 6c 64 20 62 65 20 64 65 74 65 72 6d 69 6e 65 64 ld be determined
5540: 20 77 69 74 68 6f 75 74 0a 69 74 2e 0a 0a 5c 73 without.it...\s
5550: 75 62 73 75 62 73 65 63 74 69 6f 6e 2a 7b 28 77 ubsubsection*{(w
5560: 72 61 70 2d 6c 69 6e 65 73 20 3c 66 6f 72 6d 61 rap-lines <forma
5570: 74 3e 20 2e 2e 2e 29 7d 0a 0a 42 65 68 61 76 65 t> ...)}..Behave
5580: 73 20 6c 69 6b 65 20 5c 71 7b 63 61 74 7d 2c 20 s like \q{cat},
5590: 65 78 63 65 70 74 20 74 65 78 74 20 69 73 20 61 except text is a
55a0: 63 63 75 6d 75 6c 61 74 65 64 20 61 6e 64 20 6c ccumulated and l
55b0: 69 6e 65 73 20 61 72 65 20 6f 70 74 69 6d 61 6c ines are optimal
55c0: 6c 79 0a 77 72 61 70 70 65 64 20 74 6f 20 66 69 ly.wrapped to fi
55d0: 74 20 69 6e 20 74 68 65 20 63 75 72 72 65 6e 74 t in the current
55e0: 20 77 69 64 74 68 20 61 73 20 69 6e 20 74 68 65 width as in the
55f0: 20 55 6e 69 78 20 5c 70 7b 66 6d 74 28 31 29 7d Unix \p{fmt(1)}
5600: 20 63 6f 6d 6d 61 6e 64 2e 0a 0a 5c 73 75 62 73 command...\subs
5610: 75 62 73 65 63 74 69 6f 6e 2a 7b 28 6a 75 73 74 ubsection*{(just
5620: 69 66 79 20 3c 66 6f 72 6d 61 74 3e 20 2e 2e 2e ify <format> ...
5630: 29 7d 0a 0a 4c 69 6b 65 20 5c 71 7b 77 72 61 70 )}..Like \q{wrap
5640: 2d 6c 69 6e 65 73 7d 20 65 78 63 65 70 74 20 74 -lines} except t
5650: 68 65 20 6c 69 6e 65 73 20 61 72 65 20 66 75 6c he lines are ful
5660: 6c 2d 6a 75 73 74 69 66 69 65 64 2e 0a 0a 5c 71 l-justified...\q
5670: 7b 0a 20 20 28 64 65 66 69 6e 65 20 66 75 6e 63 {. (define func
5680: 0a 20 20 20 20 27 28 64 65 66 69 6e 65 20 28 66 . '(define (f
5690: 6f 6c 64 20 6b 6f 6e 73 20 6b 6e 69 6c 20 6c 73 old kons knil ls
56a0: 29 0a 20 20 20 20 20 20 20 28 6c 65 74 20 6c 70 ). (let lp
56b0: 20 28 28 6c 73 20 6c 73 29 20 28 61 63 63 20 6b ((ls ls) (acc k
56c0: 6e 69 6c 29 29 0a 20 20 20 20 20 20 20 20 20 28 nil)). (
56d0: 69 66 20 28 6e 75 6c 6c 3f 20 6c 73 29 20 61 63 if (null? ls) ac
56e0: 63 20 28 6c 70 20 28 63 64 72 20 6c 73 29 20 28 c (lp (cdr ls) (
56f0: 6b 6f 6e 73 20 28 63 61 72 20 6c 73 29 20 61 63 kons (car ls) ac
5700: 63 29 29 29 29 29 29 0a 0a 20 20 28 64 65 66 69 c)))))).. (defi
5710: 6e 65 20 64 6f 63 0a 20 20 20 20 28 73 74 72 69 ne doc. (stri
5720: 6e 67 2d 61 70 70 65 6e 64 0a 20 20 20 20 20 20 ng-append.
5730: 22 54 68 65 20 66 75 6e 64 61 6d 65 6e 74 61 6c "The fundamental
5740: 20 6c 69 73 74 20 69 74 65 72 61 74 6f 72 2e 20 list iterator.
5750: 20 41 70 70 6c 69 65 73 20 4b 4f 4e 53 20 74 6f Applies KONS to
5760: 20 65 61 63 68 20 65 6c 65 6d 65 6e 74 20 22 0a each element ".
5770: 20 20 20 20 20 20 22 6f 66 20 4c 53 20 61 6e 64 "of LS and
5780: 20 74 68 65 20 72 65 73 75 6c 74 20 6f 66 20 74 the result of t
5790: 68 65 20 70 72 65 76 69 6f 75 73 20 61 70 70 6c he previous appl
57a0: 69 63 61 74 69 6f 6e 2c 20 62 65 67 69 6e 6e 69 ication, beginni
57b0: 6e 67 20 22 0a 20 20 20 20 20 20 22 77 69 74 68 ng ". "with
57c0: 20 4b 4e 49 4c 2e 20 20 57 69 74 68 20 4b 4f 4e KNIL. With KON
57d0: 53 20 61 73 20 43 4f 4e 53 20 61 6e 64 20 4b 4e S as CONS and KN
57e0: 49 4c 20 61 73 20 27 28 29 2c 20 65 71 75 69 76 IL as '(), equiv
57f0: 61 6c 65 6e 74 20 74 6f 20 52 45 56 45 52 53 45 alent to REVERSE
5800: 2e 22 29 29 0a 0a 20 20 28 66 6d 74 20 23 74 20 .")).. (fmt #t
5810: 28 63 6f 6c 75 6d 6e 61 72 20 28 70 72 65 74 74 (columnar (prett
5820: 79 20 66 75 6e 63 29 20 22 20 3b 20 22 20 28 6a y func) " ; " (j
5830: 75 73 74 69 66 79 20 64 6f 63 29 29 29 0a 7d 0a ustify doc))).}.
5840: 0a 6f 75 74 70 75 74 73 0a 0a 5c 70 7b 0a 20 20 .outputs..\p{.
5850: 28 64 65 66 69 6e 65 20 28 66 6f 6c 64 20 6b 6f (define (fold ko
5860: 6e 73 20 6b 6e 69 6c 20 6c 73 29 20 20 20 20 20 ns knil ls)
5870: 20 20 20 20 20 3b 20 54 68 65 20 20 20 66 75 6e ; The fun
5880: 64 61 6d 65 6e 74 61 6c 20 20 20 6c 69 73 74 20 damental list
5890: 20 20 69 74 65 72 61 74 6f 72 2e 0a 20 20 20 20 iterator..
58a0: 28 6c 65 74 20 6c 70 20 28 28 6c 73 20 6c 73 29 (let lp ((ls ls)
58b0: 20 28 61 63 63 20 6b 6e 69 6c 29 29 20 20 20 20 (acc knil))
58c0: 20 20 20 3b 20 41 70 70 6c 69 65 73 20 20 4b 4f ; Applies KO
58d0: 4e 53 20 20 74 6f 20 20 65 61 63 68 20 20 65 6c NS to each el
58e0: 65 6d 65 6e 74 20 20 6f 66 0a 20 20 20 20 20 20 ement of.
58f0: 28 69 66 20 28 6e 75 6c 6c 3f 20 6c 73 29 20 20 (if (null? ls)
5900: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
5910: 20 3b 20 4c 53 20 20 61 6e 64 20 20 74 68 65 20 ; LS and the
5920: 20 72 65 73 75 6c 74 20 6f 66 20 74 68 65 20 70 result of the p
5930: 72 65 76 69 6f 75 73 0a 20 20 20 20 20 20 20 20 revious.
5940: 20 20 61 63 63 20 20 20 20 20 20 20 20 20 20 20 acc
5950: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 3b ;
5960: 20 61 70 70 6c 69 63 61 74 69 6f 6e 2c 20 20 62 application, b
5970: 65 67 69 6e 6e 69 6e 67 20 20 77 69 74 68 20 20 eginning with
5980: 4b 4e 49 4c 2e 0a 20 20 20 20 20 20 20 20 20 20 KNIL..
5990: 28 6c 70 20 28 63 64 72 20 6c 73 29 20 20 20 20 (lp (cdr ls)
59a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 3b 20 57 ; W
59b0: 69 74 68 20 20 4b 4f 4e 53 20 20 61 73 20 43 4f ith KONS as CO
59c0: 4e 53 20 61 6e 64 20 4b 4e 49 4c 20 61 73 20 27 NS and KNIL as '
59d0: 28 29 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 (),.
59e0: 20 20 28 6b 6f 6e 73 20 28 63 61 72 20 6c 73 29 (kons (car ls)
59f0: 20 61 63 63 29 29 29 29 29 20 20 3b 20 65 71 75 acc))))) ; equ
5a00: 69 76 61 6c 65 6e 74 20 74 6f 20 52 45 56 45 52 ivalent to REVER
5a10: 53 45 2e 0a 7d 0a 0a 5c 73 75 62 73 75 62 73 65 SE..}..\subsubse
5a20: 63 74 69 6f 6e 2a 7b 28 66 6d 74 2d 66 69 6c 65 ction*{(fmt-file
5a30: 20 3c 70 61 74 68 6e 61 6d 65 3e 29 7d 0a 0a 53 <pathname>)}..S
5a40: 69 6d 70 6c 79 20 64 69 73 70 6c 61 79 65 73 20 imply displayes
5a50: 74 68 65 20 63 6f 6e 74 65 6e 74 73 20 6f 66 20 the contents of
5a60: 74 68 65 20 66 69 6c 65 20 5c 71 7b 3c 70 61 74 the file \q{<pat
5a70: 68 6e 61 6d 65 3e 7d 20 61 20 6c 69 6e 65 20 61 hname>} a line a
5a80: 74 20 61 0a 74 69 6d 65 2c 20 73 6f 20 74 68 61 t a.time, so tha
5a90: 74 20 69 6e 20 74 79 70 69 63 61 6c 20 66 6f 72 t in typical for
5aa0: 6d 61 74 74 65 72 73 20 73 75 63 68 20 61 73 20 matters such as
5ab0: 5c 71 7b 63 6f 6c 75 6d 6e 61 72 7d 20 6f 6e 6c \q{columnar} onl
5ac0: 79 20 63 6f 6e 73 74 61 6e 74 0a 6d 65 6d 6f 72 y constant.memor
5ad0: 79 20 69 73 20 63 6f 6e 73 75 6d 65 64 2c 20 6d y is consumed, m
5ae0: 61 6b 69 6e 67 20 74 68 69 73 20 73 75 69 74 61 aking this suita
5af0: 62 6c 65 20 66 6f 72 20 66 6f 72 6d 61 74 74 69 ble for formatti
5b00: 6e 67 20 66 69 6c 65 73 20 6f 66 0a 61 72 62 69 ng files of.arbi
5b10: 74 72 61 72 79 20 73 69 7a 65 2e 0a 0a 5c 73 75 trary size...\su
5b20: 62 73 75 62 73 65 63 74 69 6f 6e 2a 7b 28 6c 69 bsubsection*{(li
5b30: 6e 65 2d 6e 75 6d 62 65 72 73 20 5b 3c 73 74 61 ne-numbers [<sta
5b40: 72 74 3e 5d 29 7d 0a 0a 41 20 63 6f 6e 76 65 6e rt>])}..A conven
5b50: 69 65 6e 63 65 20 75 74 69 6c 69 74 79 2c 20 6a ience utility, j
5b60: 75 73 74 20 66 6f 72 6d 61 74 73 20 61 6e 20 69 ust formats an i
5b70: 6e 66 69 6e 69 74 65 20 73 74 72 65 61 6d 20 6f nfinite stream o
5b80: 66 20 6e 75 6d 62 65 72 73 20 28 69 6e 0a 74 68 f numbers (in.th
5b90: 65 20 63 75 72 72 65 6e 74 20 72 61 64 69 78 29 e current radix)
5ba0: 20 62 65 67 69 6e 6e 69 6e 67 20 77 69 74 68 20 beginning with
5bb0: 5c 71 7b 3c 73 74 61 72 74 3e 7d 2c 20 77 68 69 \q{<start>}, whi
5bc0: 63 68 20 64 65 66 61 75 6c 74 73 20 74 6f 20 5c ch defaults to \
5bd0: 71 7b 31 7d 2e 0a 0a 54 68 65 20 55 6e 69 78 20 q{1}...The Unix
5be0: 5c 71 7b 6e 6c 28 31 29 7d 20 75 74 69 6c 69 74 \q{nl(1)} utilit
5bf0: 79 20 63 6f 75 6c 64 20 62 65 20 69 6d 70 6c 65 y could be imple
5c00: 6d 65 6e 74 65 64 20 61 73 3a 0a 0a 5c 71 7b 0a mented as:..\q{.
5c10: 20 20 28 66 6d 74 20 23 74 20 28 63 6f 6c 75 6d (fmt #t (colum
5c20: 6e 61 72 20 36 20 27 72 69 67 68 74 20 27 69 6e nar 6 'right 'in
5c30: 66 69 6e 69 74 65 20 28 6c 69 6e 65 2d 6e 75 6d finite (line-num
5c40: 62 65 72 73 29 0a 20 20 20 20 20 20 20 20 20 20 bers).
5c50: 20 20 20 20 20 20 20 20 20 20 22 20 22 20 28 66 " " (f
5c60: 6d 74 2d 66 69 6c 65 20 22 72 65 61 64 2d 6c 69 mt-file "read-li
5c70: 6e 65 2e 73 63 6d 22 29 29 29 0a 7d 0a 0a 5c 70 ne.scm"))).}..\p
5c80: 7b 0a 20 20 20 20 20 31 20 0a 20 20 20 20 20 32 {. 1 . 2
5c90: 20 28 64 65 66 69 6e 65 20 28 72 65 61 64 2d 6c (define (read-l
5ca0: 69 6e 65 20 2e 20 6f 29 0a 20 20 20 20 20 33 20 ine . o). 3
5cb0: 20 20 28 6c 65 74 20 28 28 70 6f 72 74 20 28 69 (let ((port (i
5cc0: 66 20 28 70 61 69 72 3f 20 6f 29 20 28 63 61 72 f (pair? o) (car
5cd0: 20 6f 29 20 28 63 75 72 72 65 6e 74 2d 69 6e 70 o) (current-inp
5ce0: 75 74 2d 70 6f 72 74 29 29 29 29 0a 20 20 20 20 ut-port)))).
5cf0: 20 34 20 20 20 20 20 28 6c 65 74 20 6c 70 20 28 4 (let lp (
5d00: 28 72 65 73 20 27 28 29 29 29 0a 20 20 20 20 20 (res '())).
5d10: 35 20 20 20 20 20 20 20 28 6c 65 74 20 28 28 63 5 (let ((c
5d20: 20 28 72 65 61 64 2d 63 68 61 72 20 70 6f 72 74 (read-char port
5d30: 29 29 29 0a 20 20 20 20 20 36 20 20 20 20 20 20 ))). 6
5d40: 20 20 20 28 69 66 20 28 6f 72 20 28 65 6f 66 2d (if (or (eof-
5d50: 6f 62 6a 65 63 74 3f 20 63 29 20 28 65 71 76 3f object? c) (eqv?
5d60: 20 63 20 23 5c 6e 65 77 6c 69 6e 65 29 29 0a 20 c #\newline)).
5d70: 20 20 20 20 37 20 20 20 20 20 20 20 20 20 20 20 7
5d80: 20 20 28 6c 69 73 74 2d 3e 73 74 72 69 6e 67 20 (list->string
5d90: 28 72 65 76 65 72 73 65 20 72 65 73 29 29 0a 20 (reverse res)).
5da0: 20 20 20 20 38 20 20 20 20 20 20 20 20 20 20 20 8
5db0: 20 20 28 6c 70 20 28 63 6f 6e 73 20 63 20 72 65 (lp (cons c re
5dc0: 73 29 29 29 29 29 29 29 0a 7d 0a 0a 5c 73 65 63 s))))))).}..\sec
5dd0: 74 69 6f 6e 7b 43 20 46 6f 72 6d 61 74 74 69 6e tion{C Formattin
5de0: 67 7d 0a 0a 5c 73 75 62 73 65 63 74 69 6f 6e 7b g}..\subsection{
5df0: 43 20 46 6f 72 6d 61 74 74 69 6e 67 20 42 61 73 C Formatting Bas
5e00: 69 63 73 7d 0a 0a 46 6f 72 20 70 75 72 70 6f 73 ics}..For purpos
5e10: 65 73 20 73 75 63 68 20 61 73 20 77 72 69 74 69 es such as writi
5e20: 6e 67 20 77 72 61 70 70 65 72 73 2c 20 63 6f 64 ng wrappers, cod
5e30: 65 2d 67 65 6e 65 72 61 74 6f 72 73 2c 20 63 6f e-generators, co
5e40: 6d 70 69 6c 65 72 73 20 6f 72 0a 6f 74 68 65 72 mpilers or.other
5e50: 20 6c 61 6e 67 75 61 67 65 20 74 6f 6f 6c 73 2c language tools,
5e60: 20 70 65 6f 70 6c 65 20 6f 66 74 65 6e 20 6e 65 people often ne
5e70: 65 64 20 74 6f 20 67 65 6e 65 72 61 74 65 20 6f ed to generate o
5e80: 72 20 65 6d 69 74 20 43 20 63 6f 64 65 2e 0a 57 r emit C code..W
5e90: 69 74 68 6f 75 74 20 61 20 64 65 63 65 6e 74 20 ithout a decent
5ea0: 6c 69 62 72 61 72 79 20 66 72 61 6d 65 77 6f 72 library framewor
5eb0: 6b 20 69 74 27 73 20 64 69 66 66 69 63 75 6c 74 k it's difficult
5ec0: 20 74 6f 20 6d 61 69 6e 74 61 69 6e 20 70 72 6f to maintain pro
5ed0: 70 65 72 0a 69 6e 64 65 6e 74 61 74 69 6f 6e 2e per.indentation.
5ee0: 20 20 49 6e 20 61 64 64 69 74 69 6f 6e 2c 20 66 In addition, f
5ef0: 6f 72 20 74 68 65 20 53 63 68 65 6d 65 20 70 72 or the Scheme pr
5f00: 6f 67 72 61 6d 6d 65 72 20 69 74 27 73 20 74 65 ogrammer it's te
5f10: 64 69 6f 75 73 20 74 6f 0a 77 6f 72 6b 20 77 69 dious to.work wi
5f20: 74 68 20 61 6c 6c 20 74 68 65 20 63 6f 6e 74 65 th all the conte
5f30: 78 74 20 73 65 6e 73 69 74 69 76 69 74 69 65 73 xt sensitivities
5f40: 20 6f 66 20 43 2c 20 73 75 63 68 20 61 73 20 74 of C, such as t
5f50: 68 65 20 65 78 70 72 65 73 73 69 6f 6e 0a 76 73 he expression.vs
5f60: 2e 20 73 74 61 74 65 6d 65 6e 74 20 64 69 73 74 . statement dist
5f70: 69 6e 63 74 69 6f 6e 2c 20 73 70 65 63 69 61 6c inction, special
5f80: 20 72 75 6c 65 73 20 66 6f 72 20 77 72 69 74 69 rules for writi
5f90: 6e 67 20 70 72 65 70 72 6f 63 65 73 73 6f 72 0a ng preprocessor.
5fa0: 6d 61 63 72 6f 73 2c 20 61 6e 64 20 77 68 65 6e macros, and when
5fb0: 20 70 72 65 63 65 64 65 6e 63 65 20 72 75 6c 65 precedence rule
5fc0: 73 20 72 65 71 75 69 72 65 20 70 61 72 65 6e 74 s require parent
5fd0: 68 65 73 69 73 2e 20 20 46 6f 72 74 75 6e 61 74 hesis. Fortunat
5fe0: 65 6c 79 2c 0a 63 6f 6e 74 65 78 74 20 69 73 20 ely,.context is
5ff0: 6f 6e 65 20 74 68 69 6e 67 20 74 68 69 73 20 66 one thing this f
6000: 6f 72 6d 61 74 74 69 6e 67 20 6c 69 62 72 61 72 ormatting librar
6010: 79 20 69 73 20 67 6f 6f 64 20 61 74 20 6b 65 65 y is good at kee
6020: 70 69 6e 67 0a 74 72 61 63 6b 20 6f 66 2e 20 20 ping.track of.
6030: 54 68 65 20 43 20 66 6f 72 6d 61 74 74 69 6e 67 The C formatting
6040: 20 69 6e 74 65 72 66 61 63 65 20 74 72 69 65 73 interface tries
6050: 20 74 6f 20 6d 61 6b 65 20 69 74 20 61 73 20 65 to make it as e
6060: 61 73 79 20 61 73 0a 70 6f 73 73 69 62 6c 65 20 asy as.possible
6070: 74 6f 20 67 65 6e 65 72 61 74 65 20 43 20 63 6f to generate C co
6080: 64 65 20 77 69 74 68 6f 75 74 20 67 65 74 74 69 de without getti
6090: 6e 67 20 69 6e 20 79 6f 75 72 20 77 61 79 2e 0a ng in your way..
60a0: 0a 54 68 65 72 65 20 61 72 65 20 74 77 6f 20 61 .There are two a
60b0: 70 70 72 6f 61 63 68 65 73 20 74 6f 20 75 73 69 pproaches to usi
60c0: 6e 67 20 74 68 65 20 43 20 66 6f 72 6d 61 74 74 ng the C formatt
60d0: 69 6e 67 20 65 78 74 65 6e 73 69 6f 6e 73 20 2d ing extensions -
60e0: 0a 70 72 6f 63 65 64 75 72 61 6c 20 61 6e 64 20 .procedural and
60f0: 73 65 78 70 2d 6f 72 69 65 6e 74 65 64 20 28 64 sexp-oriented (d
6100: 65 73 63 72 69 62 65 64 20 69 6e 20 5c 72 65 66 escribed in \ref
6110: 7b 63 73 65 78 70 72 73 7d 29 2e 20 20 49 6e 20 {csexprs}). In
6120: 74 68 65 0a 70 72 6f 63 65 64 75 72 61 6c 20 69 the.procedural i
6130: 6e 74 65 72 66 61 63 65 2c 20 43 20 6f 70 65 72 nterface, C oper
6140: 61 74 6f 72 73 20 61 72 65 20 6d 61 64 65 20 61 ators are made a
6150: 76 61 69 6c 61 62 6c 65 20 61 73 20 66 6f 72 6d vailable as form
6160: 61 74 74 65 72 73 0a 77 69 74 68 20 61 20 22 63 atters.with a "c
6170: 2d 22 20 70 72 65 66 69 78 2c 20 6c 69 74 65 72 -" prefix, liter
6180: 61 6c 73 20 61 72 65 20 63 6f 6e 76 65 72 74 65 als are converte
6190: 64 20 74 6f 20 74 68 65 69 72 20 43 20 65 71 75 d to their C equ
61a0: 69 76 61 6c 65 6e 74 73 20 61 6e 64 0a 73 79 6d ivalents and.sym
61b0: 62 6f 6c 73 20 61 72 65 20 6f 75 74 70 75 74 20 bols are output
61c0: 61 73 2d 69 73 20 28 79 6f 75 27 72 65 20 72 65 as-is (you're re
61d0: 73 70 6f 6e 73 69 62 6c 65 20 66 6f 72 20 6d 61 sponsible for ma
61e0: 6b 69 6e 67 20 73 75 72 65 20 74 68 65 79 20 61 king sure they a
61f0: 72 65 0a 76 61 6c 69 64 20 43 20 69 64 65 6e 74 re.valid C ident
6200: 69 66 69 65 72 73 29 2e 20 20 49 6e 64 65 6e 74 ifiers). Indent
6210: 61 74 69 6f 6e 20 69 73 20 68 61 6e 64 6c 65 64 ation is handled
6220: 20 61 75 74 6f 6d 61 74 69 63 61 6c 6c 79 2e 0a automatically..
6230: 0a 20 20 5c 71 7b 28 66 6d 74 20 23 74 20 28 63 . \q{(fmt #t (c
6240: 2d 69 66 20 31 20 32 20 33 29 29 7d 0a 0a 6f 75 -if 1 2 3))}..ou
6250: 74 70 75 74 73 0a 0a 5c 70 7b 0a 20 20 69 66 20 tputs..\p{. if
6260: 28 31 29 20 7b 0a 20 20 20 20 20 20 32 3b 0a 20 (1) {. 2;.
6270: 20 7d 20 65 6c 73 65 20 7b 0a 20 20 20 20 20 20 } else {.
6280: 33 3b 0a 20 20 7d 0a 7d 0a 0a 49 6e 20 61 64 64 3;. }.}..In add
6290: 69 74 69 6f 6e 2c 20 74 68 65 20 66 6f 72 6d 61 ition, the forma
62a0: 74 74 65 72 20 6b 6e 6f 77 73 20 77 68 65 6e 20 tter knows when
62b0: 79 6f 75 27 72 65 20 69 6e 20 61 6e 20 65 78 70 you're in an exp
62c0: 72 65 73 73 69 6f 6e 20 61 6e 64 0a 77 68 65 6e ression and.when
62d0: 20 79 6f 75 27 72 65 20 69 6e 20 61 20 73 74 61 you're in a sta
62e0: 74 65 6d 65 6e 74 2c 20 61 6e 64 20 62 65 68 61 tement, and beha
62f0: 76 65 73 20 61 63 63 6f 72 64 69 6e 67 6c 79 2c ves accordingly,
6300: 20 73 6f 20 74 68 61 74 0a 0a 20 20 5c 71 7b 28 so that.. \q{(
6310: 66 6d 74 20 23 74 20 28 63 2d 69 66 20 28 63 2d fmt #t (c-if (c-
6320: 69 66 20 31 20 32 20 33 29 20 34 20 35 29 29 7d if 1 2 3) 4 5))}
6330: 0a 0a 6f 75 74 70 75 74 73 0a 0a 5c 70 7b 0a 20 ..outputs..\p{.
6340: 20 69 66 20 28 31 20 3f 20 32 20 3a 20 33 29 20 if (1 ? 2 : 3)
6350: 7b 0a 20 20 20 20 20 20 34 3b 0a 20 20 7d 20 65 {. 4;. } e
6360: 6c 73 65 20 7b 0a 20 20 20 20 20 20 35 3b 0a 20 lse {. 5;.
6370: 20 7d 0a 7d 0a 0a 53 69 6d 69 6c 61 72 79 2c 20 }.}..Similary,
6380: 5c 71 7b 63 2d 62 65 67 69 6e 7d 2c 20 75 73 65 \q{c-begin}, use
6390: 64 20 66 6f 72 20 73 65 71 75 65 6e 63 69 6e 67 d for sequencing
63a0: 2c 20 77 69 6c 6c 20 73 65 70 61 72 61 74 65 20 , will separate
63b0: 77 69 74 68 0a 73 65 6d 69 2d 63 6f 6c 6f 6e 73 with.semi-colons
63c0: 20 69 6e 20 61 20 73 74 61 74 65 6d 65 6e 74 20 in a statement
63d0: 61 6e 64 20 63 6f 6d 6d 61 73 20 69 6e 20 61 6e and commas in an
63e0: 20 65 78 70 72 65 73 73 69 6f 6e 2e 0a 0a 4d 6f expression...Mo
63f0: 72 65 6f 76 65 72 2c 20 77 65 20 61 6c 73 6f 20 reover, we also
6400: 6b 65 65 70 20 74 72 61 63 6b 20 6f 66 20 74 68 keep track of th
6410: 65 20 66 69 6e 61 6c 20 65 78 70 72 65 73 73 69 e final expressi
6420: 6f 6e 20 69 6e 20 61 20 66 75 6e 63 74 69 6f 6e on in a function
6430: 0a 61 6e 64 20 69 6e 73 65 72 74 20 72 65 74 75 .and insert retu
6440: 72 6e 73 20 66 6f 72 20 79 6f 75 3a 0a 0a 20 20 rns for you:..
6450: 5c 71 7b 28 66 6d 74 20 23 74 20 28 63 2d 66 75 \q{(fmt #t (c-fu
6460: 6e 20 27 69 6e 74 20 27 66 6f 6f 20 27 28 29 20 n 'int 'foo '()
6470: 28 63 2d 69 66 20 28 63 2d 69 66 20 31 20 32 20 (c-if (c-if 1 2
6480: 33 29 20 34 20 35 29 29 29 7d 0a 0a 6f 75 74 70 3) 4 5)))}..outp
6490: 75 74 73 0a 0a 5c 70 7b 0a 20 20 69 6e 74 20 66 uts..\p{. int f
64a0: 6f 6f 20 28 29 20 7b 0a 20 20 20 20 20 20 69 66 oo () {. if
64b0: 20 28 31 20 3f 20 32 20 3a 20 33 29 20 7b 0a 20 (1 ? 2 : 3) {.
64c0: 20 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 return
64d0: 34 3b 0a 20 20 20 20 20 20 7d 20 65 6c 73 65 20 4;. } else
64e0: 7b 0a 20 20 20 20 20 20 20 20 20 20 72 65 74 75 {. retu
64f0: 72 6e 20 35 3b 0a 20 20 20 20 20 20 7d 0a 20 20 rn 5;. }.
6500: 7d 0a 7d 0a 0a 61 6c 74 68 6f 75 67 68 20 69 74 }.}..although it
6510: 20 6b 6e 6f 77 73 20 74 68 61 74 20 76 6f 69 64 knows that void
6520: 20 66 75 6e 63 74 69 6f 6e 73 20 64 6f 6e 27 74 functions don't
6530: 20 72 65 74 75 72 6e 2e 0a 0a 53 77 69 74 63 68 return...Switch
6540: 20 73 74 61 74 65 6d 65 6e 74 73 20 69 6e 73 65 statements inse
6550: 72 74 20 62 72 65 61 6b 73 20 62 79 20 64 65 66 rt breaks by def
6560: 61 75 6c 74 20 69 66 20 74 68 65 79 20 64 6f 6e ault if they don
6570: 27 74 20 72 65 74 75 72 6e 3a 0a 0a 5c 71 7b 0a 't return:..\q{.
6580: 20 20 28 66 6d 74 20 23 74 20 28 63 2d 73 77 69 (fmt #t (c-swi
6590: 74 63 68 20 27 79 0a 20 20 20 20 20 20 20 20 20 tch 'y.
65a0: 20 20 20 28 63 2d 63 61 73 65 20 31 20 28 63 2b (c-case 1 (c+
65b0: 3d 20 27 78 20 31 29 29 0a 20 20 20 20 20 20 20 = 'x 1)).
65c0: 20 20 20 20 20 28 63 2d 64 65 66 61 75 6c 74 20 (c-default
65d0: 28 63 2b 3d 20 27 78 20 32 29 29 29 29 0a 7d 0a (c+= 'x 2)))).}.
65e0: 0a 5c 70 7b 0a 20 20 73 77 69 74 63 68 20 28 79 .\p{. switch (y
65f0: 29 20 7b 0a 20 20 20 20 20 20 63 61 73 65 20 31 ) {. case 1
6600: 3a 0a 20 20 20 20 20 20 20 20 20 20 78 20 2b 3d :. x +=
6610: 20 31 3b 0a 20 20 20 20 20 20 20 20 20 20 62 72 1;. br
6620: 65 61 6b 3b 0a 20 20 20 20 20 20 64 65 66 61 75 eak;. defau
6630: 6c 74 3a 0a 20 20 20 20 20 20 20 20 20 20 78 20 lt:. x
6640: 2b 3d 20 32 3b 0a 20 20 20 20 20 20 20 20 20 20 += 2;.
6650: 62 72 65 61 6b 3b 0a 20 20 7d 0a 7d 0a 0a 74 68 break;. }.}..th
6660: 6f 75 67 68 20 79 6f 75 20 63 61 6e 20 65 78 70 ough you can exp
6670: 6c 69 63 69 74 6c 79 20 66 61 6c 6c 74 68 72 6f licitly fallthro
6680: 75 67 68 20 69 66 20 79 6f 75 20 77 61 6e 74 3a ugh if you want:
6690: 0a 0a 5c 71 7b 0a 20 20 28 66 6d 74 20 23 74 20 ..\q{. (fmt #t
66a0: 28 63 2d 73 77 69 74 63 68 20 27 79 0a 20 20 20 (c-switch 'y.
66b0: 20 20 20 20 20 20 20 20 20 28 63 2d 63 61 73 65 (c-case
66c0: 2f 66 61 6c 6c 74 68 72 6f 75 67 68 20 31 20 28 /fallthrough 1 (
66d0: 63 2b 3d 20 27 78 20 31 29 29 0a 20 20 20 20 20 c+= 'x 1)).
66e0: 20 20 20 20 20 20 20 28 63 2d 64 65 66 61 75 6c (c-defaul
66f0: 74 20 28 63 2b 3d 20 27 78 20 32 29 29 29 29 0a t (c+= 'x 2)))).
6700: 7d 0a 0a 5c 70 7b 0a 20 20 73 77 69 74 63 68 20 }..\p{. switch
6710: 28 79 29 20 7b 0a 20 20 20 20 20 20 63 61 73 65 (y) {. case
6720: 20 31 3a 0a 20 20 20 20 20 20 20 20 20 20 78 20 1:. x
6730: 2b 3d 20 31 3b 0a 20 20 20 20 20 20 64 65 66 61 += 1;. defa
6740: 75 6c 74 3a 0a 20 20 20 20 20 20 20 20 20 20 78 ult:. x
6750: 20 2b 3d 20 32 3b 0a 20 20 20 20 20 20 20 20 20 += 2;.
6760: 20 62 72 65 61 6b 3b 0a 20 20 7d 0a 7d 0a 0a 4f break;. }.}..O
6770: 70 65 72 61 74 6f 72 73 20 61 72 65 20 61 76 61 perators are ava
6780: 69 6c 61 62 6c 65 20 77 69 74 68 20 6a 75 73 74 ilable with just
6790: 20 61 20 22 63 22 20 70 72 65 66 69 78 2c 20 65 a "c" prefix, e
67a0: 2e 67 2e 20 63 2b 2c 20 63 2d 2c 20 63 2a 2c 20 .g. c+, c-, c*,
67b0: 63 2f 2c 0a 65 74 63 2e 20 20 5c 71 7b 63 2b 2b c/,.etc. \q{c++
67c0: 7d 20 69 73 20 61 20 70 72 65 66 69 78 20 6f 70 } is a prefix op
67d0: 65 72 61 74 6f 72 2c 20 5c 71 7b 63 2b 2b 2f 70 erator, \q{c++/p
67e0: 6f 73 74 7d 20 69 73 20 70 6f 73 74 66 69 78 2e ost} is postfix.
67f0: 20 20 7c 7c 2c 20 7c 20 61 6e 64 0a 7c 3d 20 61 ||, | and.|= a
6800: 72 65 20 77 72 69 74 74 65 6e 20 61 73 20 5c 71 re written as \q
6810: 7b 63 2d 6f 72 7d 2c 20 5c 71 7b 63 2d 62 69 74 {c-or}, \q{c-bit
6820: 2d 6f 72 7d 20 61 6e 64 20 5c 71 7b 63 2d 62 69 -or} and \q{c-bi
6830: 74 2d 6f 72 3d 7d 20 72 65 73 70 65 63 74 69 76 t-or=} respectiv
6840: 65 6c 79 2e 0a 0a 46 75 6e 63 74 69 6f 6e 20 61 ely...Function a
6850: 70 70 6c 69 63 61 74 69 6f 6e 73 20 61 72 65 20 pplications are
6860: 77 72 69 74 74 65 6e 20 77 69 74 68 20 5c 71 7b written with \q{
6870: 63 2d 61 70 70 6c 79 7d 2e 20 20 4f 74 68 65 72 c-apply}. Other
6880: 20 63 6f 6e 74 72 6f 6c 0a 73 74 72 75 63 74 75 control.structu
6890: 72 65 73 20 73 75 63 68 20 61 73 20 5c 71 7b 63 res such as \q{c
68a0: 2d 66 6f 72 7d 20 61 6e 64 20 5c 71 7b 63 2d 77 -for} and \q{c-w
68b0: 68 69 6c 65 7d 20 77 6f 72 6b 20 61 73 20 65 78 hile} work as ex
68c0: 70 65 63 74 65 64 2e 20 20 54 68 65 20 66 75 6c pected. The ful
68d0: 6c 0a 6c 69 73 74 20 69 73 20 69 6e 20 74 68 65 l.list is in the
68e0: 20 70 72 6f 63 65 64 75 72 65 20 69 6e 64 65 78 procedure index
68f0: 20 62 65 6c 6f 77 2e 0a 0a 57 68 65 6e 20 61 20 below...When a
6900: 43 20 66 6f 72 6d 61 74 74 65 72 20 65 6e 63 6f C formatter enco
6910: 75 6e 74 65 72 73 20 61 6e 20 6f 62 6a 65 63 74 unters an object
6920: 20 69 74 20 64 6f 65 73 6e 27 74 20 6b 6e 6f 77 it doesn't know
6930: 20 68 6f 77 20 74 6f 20 77 72 69 74 65 0a 28 69 how to write.(i
6940: 6e 63 6c 75 64 69 6e 67 20 6c 69 73 74 73 20 61 ncluding lists a
6950: 6e 64 20 72 65 63 6f 72 64 73 29 2c 20 69 74 20 nd records), it
6960: 6f 75 74 70 75 74 73 20 74 68 65 6d 20 61 63 63 outputs them acc
6970: 6f 72 64 69 6e 67 20 74 6f 20 74 68 65 0a 66 6f ording to the.fo
6980: 72 6d 61 74 20 73 74 61 74 65 27 73 20 63 75 72 rmat state's cur
6990: 72 65 6e 74 20 5c 71 7b 27 67 65 6e 7d 20 76 61 rent \q{'gen} va
69a0: 72 69 61 62 6c 65 2e 20 20 54 68 69 73 20 61 6c riable. This al
69b0: 6c 6f 77 73 20 79 6f 75 20 74 6f 20 73 70 65 63 lows you to spec
69c0: 69 66 79 0a 67 65 6e 65 72 61 74 6f 72 73 20 66 ify.generators f
69d0: 6f 72 20 79 6f 75 72 20 6f 77 6e 20 74 79 70 65 or your own type
69e0: 73 2c 20 65 2e 67 2e 20 69 66 20 79 6f 75 20 61 s, e.g. if you a
69f0: 72 65 20 75 73 69 6e 67 20 79 6f 75 72 20 6f 77 re using your ow
6a00: 6e 20 41 53 54 0a 72 65 63 6f 72 64 73 20 69 6e n AST.records in
6a10: 20 61 20 63 6f 6d 70 69 6c 65 72 2e 0a 0a 49 66 a compiler...If
6a20: 20 74 68 65 20 5c 71 7b 27 67 65 6e 7d 20 76 61 the \q{'gen} va
6a30: 72 69 61 62 6c 65 20 69 73 6e 27 74 20 73 65 74 riable isn't set
6a40: 20 69 74 20 64 65 66 61 75 6c 74 73 20 74 6f 20 it defaults to
6a50: 74 68 65 20 5c 71 7b 63 2d 65 78 70 72 2f 73 65 the \q{c-expr/se
6a60: 78 70 7d 0a 70 72 6f 63 65 64 75 72 65 2c 20 77 xp}.procedure, w
6a70: 68 69 63 68 20 66 6f 72 6d 61 74 73 20 61 6e 20 hich formats an
6a80: 73 2d 65 78 70 72 65 73 73 69 6f 6e 20 61 73 20 s-expression as
6a90: 69 66 20 69 74 20 77 65 72 65 20 43 20 63 6f 64 if it were C cod
6aa0: 65 2e 20 20 54 68 75 73 0a 69 6e 73 74 65 61 64 e. Thus.instead
6ab0: 20 6f 66 20 5c 71 7b 63 2d 61 70 70 6c 79 7d 20 of \q{c-apply}
6ac0: 79 6f 75 20 63 61 6e 20 6a 75 73 74 20 75 73 65 you can just use
6ad0: 20 61 20 6c 69 73 74 2e 20 20 54 68 65 20 66 75 a list. The fu
6ae0: 6c 6c 20 41 50 49 20 69 73 0a 61 76 61 69 6c 61 ll API is.availa
6af0: 62 6c 65 20 76 69 61 20 6e 6f 72 6d 61 6c 20 73 ble via normal s
6b00: 2d 65 78 70 72 65 73 73 69 6f 6e 73 20 2d 20 66 -expressions - f
6b10: 6f 72 6d 61 74 74 65 72 73 20 74 68 61 74 20 61 ormatters that a
6b20: 72 65 6e 27 74 20 6b 65 79 77 6f 72 64 73 0a 69 ren't keywords.i
6b30: 6e 20 43 20 61 72 65 20 70 72 65 66 69 78 65 64 n C are prefixed
6b40: 20 77 69 74 68 20 61 20 25 20 6f 72 20 6f 74 68 with a % or oth
6b50: 65 72 77 69 73 65 20 6d 61 64 65 20 69 6e 76 61 erwise made inva
6b60: 6c 69 64 20 43 20 69 64 65 6e 74 69 66 69 65 72 lid C identifier
6b70: 73 20 73 6f 0a 74 68 61 74 20 74 68 65 79 20 63 s so.that they c
6b80: 61 6e 27 74 20 62 65 20 63 6f 6e 66 75 73 65 64 an't be confused
6b90: 20 77 69 74 68 20 66 75 6e 63 74 69 6f 6e 20 61 with function a
6ba0: 70 70 6c 69 63 61 74 69 6f 6e 2e 0a 0a 0a 5c 73 pplication....\s
6bb0: 75 62 73 65 63 74 69 6f 6e 7b 43 20 50 72 65 70 ubsection{C Prep
6bc0: 72 6f 63 65 73 73 6f 72 20 46 6f 72 6d 61 74 74 rocessor Formatt
6bd0: 69 6e 67 7d 0a 0a 43 20 70 72 65 70 72 6f 63 65 ing}..C preproce
6be0: 73 73 6f 72 20 66 6f 72 6d 61 74 74 65 72 73 20 ssor formatters
6bf0: 61 6c 73 6f 20 70 72 6f 70 65 72 6c 79 20 68 61 also properly ha
6c00: 6e 64 6c 65 20 74 68 65 69 72 20 73 75 72 72 6f ndle their surro
6c10: 75 6e 64 69 6e 67 0a 63 6f 6e 74 65 78 74 2c 20 unding.context,
6c20: 73 6f 20 79 6f 75 20 63 61 6e 20 73 61 66 65 6c so you can safel
6c30: 79 20 69 6e 74 65 72 6d 69 78 20 74 68 65 6d 20 y intermix them
6c40: 69 6e 20 74 68 65 20 6e 6f 72 6d 61 6c 20 66 6c in the normal fl
6c50: 6f 77 20 6f 66 20 43 0a 63 6f 64 65 2e 0a 0a 5c ow of C.code...\
6c60: 71 7b 0a 20 20 28 66 6d 74 20 23 74 20 28 63 2d q{. (fmt #t (c-
6c70: 73 77 69 74 63 68 20 27 79 0a 20 20 20 20 20 20 switch 'y.
6c80: 20 20 20 20 20 20 28 63 2d 63 61 73 65 20 31 20 (c-case 1
6c90: 28 63 3d 20 27 78 20 31 29 29 0a 20 20 20 20 20 (c= 'x 1)).
6ca0: 20 20 20 20 20 20 20 28 63 70 70 2d 69 66 64 65 (cpp-ifde
6cb0: 66 20 27 48 5f 54 57 4f 20 28 63 2d 63 61 73 65 f 'H_TWO (c-case
6cc0: 20 32 20 28 63 3d 20 27 78 20 34 29 29 29 0a 20 2 (c= 'x 4))).
6cd0: 20 20 20 20 20 20 20 20 20 20 20 28 63 2d 64 65 (c-de
6ce0: 66 61 75 6c 74 20 28 63 3d 20 27 78 20 35 29 29 fault (c= 'x 5))
6cf0: 29 29 0a 7d 0a 0a 5c 70 7b 0a 20 20 73 77 69 74 )).}..\p{. swit
6d00: 63 68 20 28 79 29 20 7b 0a 20 20 20 20 20 20 63 ch (y) {. c
6d10: 61 73 65 20 31 3a 0a 20 20 20 20 20 20 20 20 20 ase 1:.
6d20: 20 78 20 3d 20 31 3b 0a 20 20 20 20 20 20 20 20 x = 1;.
6d30: 20 20 62 72 65 61 6b 3b 0a 0a 20 20 23 69 66 64 break;.. #ifd
6d40: 65 66 20 48 5f 54 57 4f 0a 20 20 20 20 20 20 63 ef H_TWO. c
6d50: 61 73 65 20 32 3a 0a 20 20 20 20 20 20 20 20 20 ase 2:.
6d60: 20 78 20 3d 20 34 3b 0a 20 20 20 20 20 20 20 20 x = 4;.
6d70: 20 20 62 72 65 61 6b 3b 0a 20 20 23 65 6e 64 69 break;. #endi
6d80: 66 20 2f 2a 20 48 5f 54 57 4f 20 2a 2f 0a 20 20 f /* H_TWO */.
6d90: 20 20 20 20 64 65 66 61 75 6c 74 3a 0a 20 20 20 default:.
6da0: 20 20 20 20 20 20 20 78 20 3d 20 35 3b 0a 20 20 x = 5;.
6db0: 20 20 20 20 20 20 20 20 62 72 65 61 6b 3b 0a 20 break;.
6dc0: 20 7d 0a 7d 0a 0a 4d 61 63 72 6f 73 20 63 61 6e }.}..Macros can
6dd0: 20 62 65 20 68 61 6e 64 6c 65 64 20 77 69 74 68 be handled with
6de0: 20 5c 71 7b 63 70 70 2d 64 65 66 69 6e 65 7d 2c \q{cpp-define},
6df0: 20 77 68 69 63 68 20 6b 6e 6f 77 73 20 74 6f 20 which knows to
6e00: 77 72 61 70 0a 69 6e 64 69 76 69 64 75 61 6c 20 wrap.individual
6e10: 76 61 72 69 61 62 6c 65 20 72 65 66 65 72 65 6e variable referen
6e20: 63 65 73 20 69 6e 20 70 61 72 65 6e 74 68 65 73 ces in parenthes
6e30: 69 73 3a 0a 0a 20 20 5c 71 7b 28 66 6d 74 20 23 is:.. \q{(fmt #
6e40: 74 20 28 63 70 70 2d 64 65 66 69 6e 65 20 27 28 t (cpp-define '(
6e50: 6d 69 6e 20 78 20 79 29 20 28 63 2d 69 66 20 28 min x y) (c-if (
6e60: 63 3c 20 27 78 20 27 79 29 20 27 78 20 27 79 29 c< 'x 'y) 'x 'y)
6e70: 29 29 7d 0a 0a 5c 70 7b 0a 20 20 23 64 65 66 69 ))}..\p{. #defi
6e80: 6e 65 20 6d 69 6e 28 78 2c 20 79 29 20 28 28 28 ne min(x, y) (((
6e90: 78 29 20 3c 20 28 79 29 29 20 3f 20 28 78 29 20 x) < (y)) ? (x)
6ea0: 3a 20 28 79 29 29 0a 7d 0a 0a 41 73 20 77 69 74 : (y)).}..As wit
6eb0: 68 20 61 6c 6c 20 43 20 66 6f 72 6d 61 74 74 65 h all C formatte
6ec0: 72 73 2c 20 74 68 65 20 43 50 50 20 6f 75 74 70 rs, the CPP outp
6ed0: 75 74 20 69 73 20 70 72 65 74 74 79 20 70 72 69 ut is pretty pri
6ee0: 6e 74 65 64 20 61 73 0a 6e 65 65 64 65 64 2c 20 nted as.needed,
6ef0: 61 6e 64 20 69 66 20 69 74 20 77 72 61 70 73 20 and if it wraps
6f00: 6f 76 65 72 20 73 65 76 65 72 61 6c 20 6c 69 6e over several lin
6f10: 65 73 20 74 68 65 20 6c 69 6e 65 73 20 61 72 65 es the lines are
6f20: 20 74 65 72 6d 69 6e 61 74 65 64 0a 77 69 74 68 terminated.with
6f30: 20 61 20 62 61 63 6b 73 6c 61 73 68 2e 0a 0a 54 a backslash...T
6f40: 6f 20 77 72 69 74 65 20 61 20 43 20 68 65 61 64 o write a C head
6f50: 65 72 20 66 69 6c 65 20 74 68 61 74 20 69 73 20 er file that is
6f60: 69 6e 63 6c 75 64 65 64 20 61 74 20 6d 6f 73 74 included at most
6f70: 20 6f 6e 63 65 2c 20 79 6f 75 20 63 61 6e 20 77 once, you can w
6f80: 72 61 70 0a 74 68 65 20 65 6e 74 69 72 65 20 62 rap.the entire b
6f90: 6f 64 79 20 69 6e 20 5c 71 7b 63 70 70 2d 77 72 ody in \q{cpp-wr
6fa0: 61 70 2d 68 65 61 64 65 72 7d 3a 0a 0a 5c 71 7b ap-header}:..\q{
6fb0: 0a 20 20 28 66 6d 74 20 23 74 20 28 63 70 70 2d . (fmt #t (cpp-
6fc0: 77 72 61 70 2d 68 65 61 64 65 72 20 22 46 4f 4f wrap-header "FOO
6fd0: 5f 48 22 0a 20 20 20 20 20 20 20 20 20 20 20 20 _H".
6fe0: 28 63 2d 65 78 74 65 72 6e 20 28 63 2d 70 72 6f (c-extern (c-pro
6ff0: 74 6f 74 79 70 65 20 27 69 6e 74 20 27 66 6f 6f totype 'int 'foo
7000: 20 27 28 29 29 29 29 29 0a 7d 0a 0a 5c 70 7b 0a '())))).}..\p{.
7010: 20 20 23 69 66 6e 64 65 66 20 46 4f 4f 5f 48 0a #ifndef FOO_H.
7020: 20 20 23 64 65 66 69 6e 65 20 46 4f 4f 5f 48 0a #define FOO_H.
7030: 0a 20 20 65 78 74 65 72 6e 20 69 6e 74 20 66 6f . extern int fo
7040: 6f 20 28 29 3b 0a 0a 20 20 23 65 6e 64 69 66 20 o ();.. #endif
7050: 2f 2a 20 21 20 46 4f 4f 5f 48 20 2a 2f 0a 7d 0a /* ! FOO_H */.}.
7060: 0a 0a 5c 73 75 62 73 65 63 74 69 6f 6e 7b 43 75 ..\subsection{Cu
7070: 73 74 6f 6d 69 7a 69 6e 67 20 43 20 53 74 79 6c stomizing C Styl
7080: 65 7d 0a 0a 54 68 65 20 6f 75 74 70 75 74 20 75 e}..The output u
7090: 73 65 73 20 61 20 73 69 6d 70 6c 69 66 69 65 64 ses a simplified
70a0: 20 4b 26 52 20 73 74 79 6c 65 20 77 69 74 68 20 K&R style with
70b0: 34 20 73 70 61 63 65 73 20 66 6f 72 20 69 6e 64 4 spaces for ind
70c0: 65 6e 74 61 74 69 6f 6e 0a 62 79 20 64 65 66 61 entation.by defa
70d0: 75 6c 74 2e 20 20 54 68 65 20 66 6f 6c 6c 6f 77 ult. The follow
70e0: 69 6e 67 20 73 74 61 74 65 20 76 61 72 69 61 62 ing state variab
70f0: 6c 65 73 20 6c 65 74 20 79 6f 75 20 6f 76 65 72 les let you over
7100: 72 69 64 65 20 74 68 65 0a 73 74 79 6c 65 3a 0a ride the.style:.
7110: 0a 5c 73 75 62 73 75 62 73 65 63 74 69 6f 6e 2a .\subsubsection*
7120: 7b 27 69 6e 64 65 6e 74 2d 73 70 61 63 65 7d 0a {'indent-space}.
7130: 0a 68 6f 77 20 6d 61 6e 79 20 73 70 61 63 65 73 .how many spaces
7140: 20 74 6f 20 69 6e 64 65 6e 74 20 62 6f 64 69 65 to indent bodie
7150: 73 2c 20 64 65 66 61 75 6c 74 20 5c 71 7b 34 7d s, default \q{4}
7160: 0a 0a 5c 73 75 62 73 75 62 73 65 63 74 69 6f 6e ..\subsubsection
7170: 2a 7b 27 73 77 69 74 63 68 2d 69 6e 64 65 6e 74 *{'switch-indent
7180: 2d 73 70 61 63 65 7d 0a 0a 68 6f 77 20 6d 61 6e -space}..how man
7190: 79 20 73 70 61 63 65 73 20 74 6f 20 69 6e 64 65 y spaces to inde
71a0: 6e 74 20 73 77 69 74 63 68 20 63 6c 61 75 73 65 nt switch clause
71b0: 73 2c 20 61 6c 73 6f 20 64 65 66 61 75 6c 74 73 s, also defaults
71c0: 20 74 6f 20 5c 71 7b 34 7d 0a 0a 5c 73 75 62 73 to \q{4}..\subs
71d0: 75 62 73 65 63 74 69 6f 6e 2a 7b 27 6e 65 77 6c ubsection*{'newl
71e0: 69 6e 65 2d 62 65 66 6f 72 65 2d 62 72 61 63 65 ine-before-brace
71f0: 3f 7d 0a 0a 69 6e 73 65 72 74 20 61 20 6e 65 77 ?}..insert a new
7200: 6c 69 6e 65 20 62 65 66 6f 72 65 20 61 6e 20 6f line before an o
7210: 70 65 6e 20 62 72 61 63 65 20 28 6e 6f 6e 2d 4b pen brace (non-K
7220: 26 52 29 2c 20 64 65 66 61 75 6c 74 73 20 20 74 &R), defaults t
7230: 6f 20 5c 71 7b 23 66 7d 0a 0a 5c 73 75 62 73 75 o \q{#f}..\subsu
7240: 62 73 65 63 74 69 6f 6e 2a 7b 27 62 72 61 63 65 bsection*{'brace
7250: 6c 65 73 73 2d 62 6f 64 69 65 73 3f 7d 0a 0a 6f less-bodies?}..o
7260: 6d 69 74 20 62 72 61 63 65 73 20 77 68 65 6e 20 mit braces when
7270: 77 65 20 63 61 6e 20 70 72 6f 76 65 20 74 68 65 we can prove the
7280: 79 20 61 72 65 6e 27 74 20 6e 65 65 64 65 64 0a y aren't needed.
7290: 0a 5c 73 75 62 73 75 62 73 65 63 74 69 6f 6e 2a .\subsubsection*
72a0: 7b 27 6e 6f 6e 2d 73 70 61 63 65 64 2d 6f 70 73 {'non-spaced-ops
72b0: 3f 7d 0a 0a 6f 6d 69 74 20 73 70 61 63 65 73 20 ?}..omit spaces
72c0: 62 65 74 77 65 65 6e 20 6f 70 65 72 61 74 6f 72 between operator
72d0: 73 20 61 6e 64 20 6f 70 65 72 61 6e 64 73 20 66 s and operands f
72e0: 6f 72 20 67 72 6f 75 70 73 20 6f 66 20 76 61 72 or groups of var
72f0: 69 61 62 6c 65 73 20 61 6e 64 0a 6c 69 74 65 72 iables and.liter
7300: 61 6c 73 20 28 65 2e 67 2e 20 22 61 2b 62 2b 33 als (e.g. "a+b+3
7310: 22 20 69 6e 73 74 65 61 64 20 6f 66 20 22 61 20 " instead of "a
7320: 2b 20 62 20 2b 20 33 22 7d 0a 0a 5c 73 75 62 73 + b + 3"}..\subs
7330: 75 62 73 65 63 74 69 6f 6e 2a 7b 27 6e 6f 2d 77 ubsection*{'no-w
7340: 72 61 70 3f 7d 0a 0a 44 6f 6e 27 74 20 77 72 61 rap?}..Don't wra
7350: 70 20 66 75 6e 63 74 69 6f 6e 20 63 61 6c 6c 73 p function calls
7360: 20 61 6e 64 20 6c 6f 6e 67 20 6f 70 65 72 61 74 and long operat
7370: 6f 72 20 67 72 6f 75 70 73 20 6f 76 65 72 20 6d or groups over m
7380: 75 6c 69 74 70 6c 65 0a 6c 69 6e 65 73 2e 20 20 ulitple.lines.
7390: 46 75 6e 63 74 69 6f 6e 73 20 61 6e 64 20 63 6f Functions and co
73a0: 6e 74 72 6f 6c 20 73 74 72 75 63 74 75 72 65 73 ntrol structures
73b0: 20 77 69 6c 6c 20 73 74 69 6c 6c 20 75 73 65 20 will still use
73c0: 6d 75 6c 74 69 70 6c 65 0a 6c 69 6e 65 73 2e 0a multiple.lines..
73d0: 0a 54 68 65 20 43 20 66 6f 72 6d 61 74 74 65 72 .The C formatter
73e0: 73 20 61 6c 73 6f 20 72 65 73 70 65 63 74 20 74 s also respect t
73f0: 68 65 20 5c 71 7b 27 72 61 64 69 78 7d 20 61 6e he \q{'radix} an
7400: 64 20 5c 71 7b 27 70 72 65 63 69 73 69 6f 6e 7d d \q{'precision}
7410: 20 73 65 74 74 69 6e 67 73 2e 0a 0a 0a 5c 73 75 settings....\su
7420: 62 73 65 63 74 69 6f 6e 7b 43 20 46 6f 72 6d 61 bsection{C Forma
7430: 74 74 65 72 20 49 6e 64 65 78 7d 0a 0a 5c 73 75 tter Index}..\su
7440: 62 73 75 62 73 65 63 74 69 6f 6e 2a 7b 28 63 2d bsubsection*{(c-
7450: 69 66 20 3c 63 6f 6e 64 69 74 69 6f 6e 3e 20 3c if <condition> <
7460: 70 61 73 73 3e 20 5b 3c 66 61 69 6c 3e 20 5b 3c pass> [<fail> [<
7470: 63 6f 6e 64 69 74 69 6f 6e 32 3e 20 3c 70 61 73 condition2> <pas
7480: 73 32 3e 20 2e 2e 2e 5d 5d 29 7d 0a 0a 50 72 69 s2> ...]])}..Pri
7490: 6e 74 20 61 20 63 68 61 69 6e 20 6f 66 20 69 66 nt a chain of if
74a0: 2f 65 6c 73 65 20 63 6f 6e 64 69 74 69 6f 6e 73 /else conditions
74b0: 2e 20 20 55 73 65 20 61 20 66 69 6e 61 6c 20 63 . Use a final c
74c0: 6f 6e 64 69 74 69 6f 6e 20 6f 66 20 5c 71 7b 27 ondition of \q{'
74d0: 65 6c 73 65 7d 0a 66 6f 72 20 61 20 66 69 6e 61 else}.for a fina
74e0: 6c 20 65 6c 73 65 20 63 6c 61 75 73 65 2e 0a 0a l else clause...
74f0: 5c 73 75 62 73 75 62 73 65 63 74 69 6f 6e 2a 7b \subsubsection*{
7500: 28 63 2d 66 6f 72 20 3c 69 6e 69 74 3e 20 3c 63 (c-for <init> <c
7510: 6f 6e 64 69 74 69 6f 6e 3e 20 3c 75 70 64 61 74 ondition> <updat
7520: 65 3e 20 3c 62 6f 64 79 3e 20 2e 2e 2e 29 7d 0a e> <body> ...)}.
7530: 5c 73 75 62 73 75 62 73 65 63 74 69 6f 6e 2a 7b \subsubsection*{
7540: 28 63 2d 77 68 69 6c 65 20 3c 63 6f 6e 64 69 74 (c-while <condit
7550: 69 6f 6e 3e 20 3c 62 6f 64 79 3e 20 2e 2e 2e 29 ion> <body> ...)
7560: 7d 0a 0a 42 61 73 69 63 20 6c 6f 6f 70 20 63 6f }..Basic loop co
7570: 6e 73 74 72 75 63 74 73 2e 0a 0a 5c 73 75 62 73 nstructs...\subs
7580: 75 62 73 65 63 74 69 6f 6e 2a 7b 28 63 2d 66 75 ubsection*{(c-fu
7590: 6e 20 3c 74 79 70 65 3e 20 3c 6e 61 6d 65 3e 20 n <type> <name>
75a0: 3c 70 61 72 61 6d 73 3e 20 3c 62 6f 64 79 3e 20 <params> <body>
75b0: 2e 2e 2e 29 7d 0a 5c 73 75 62 73 75 62 73 65 63 ...)}.\subsubsec
75c0: 74 69 6f 6e 2a 7b 28 63 2d 70 72 6f 74 6f 74 79 tion*{(c-prototy
75d0: 70 65 20 3c 74 79 70 65 3e 20 3c 6e 61 6d 65 3e pe <type> <name>
75e0: 20 3c 70 61 72 61 6d 73 3e 29 7d 0a 0a 4f 75 74 <params>)}..Out
75f0: 70 75 74 20 61 20 66 75 6e 63 74 69 6f 6e 20 6f put a function o
7600: 72 20 66 75 6e 63 74 69 6f 6e 20 70 72 6f 74 6f r function proto
7610: 74 79 70 65 2e 20 20 54 68 65 20 70 61 72 61 6d type. The param
7620: 65 74 65 72 73 20 73 68 6f 75 6c 64 20 62 65 20 eters should be
7630: 61 0a 6c 69 73 74 20 32 2d 65 6c 65 6d 65 6e 74 a.list 2-element
7640: 20 6c 69 73 74 73 20 6f 66 20 74 68 65 20 66 6f lists of the fo
7650: 72 6d 20 5c 71 7b 28 3c 70 61 72 61 6d 2d 74 79 rm \q{(<param-ty
7660: 70 65 3e 20 3c 70 61 72 61 6d 2d 6e 61 6d 65 3e pe> <param-name>
7670: 29 7d 2c 0a 77 68 69 63 68 20 61 72 65 20 6f 75 )},.which are ou
7680: 74 70 75 74 20 77 69 74 68 20 44 53 50 2e 20 20 tput with DSP.
7690: 41 20 70 61 72 61 6d 65 74 65 72 20 63 61 6e 20 A parameter can
76a0: 62 65 20 61 62 62 72 65 76 69 61 74 65 64 20 61 be abbreviated a
76b0: 73 20 6a 75 73 74 20 74 68 65 0a 73 79 6d 62 6f s just the.symbo
76c0: 6c 20 6e 61 6d 65 2c 20 6f 72 20 5c 71 7b 23 66 l name, or \q{#f
76d0: 7d 20 63 61 6e 20 62 65 20 70 61 73 73 65 64 20 } can be passed
76e0: 61 73 20 74 68 65 20 74 79 70 65 2c 20 69 6e 20 as the type, in
76f0: 77 68 69 63 68 20 63 61 73 65 20 74 68 65 0a 5c which case the.\
7700: 71 7b 27 64 65 66 61 75 6c 74 2d 74 79 70 65 7d q{'default-type}
7710: 20 73 74 61 74 65 20 76 61 72 69 61 62 6c 65 20 state variable
7720: 69 73 20 75 73 65 64 2e 20 20 54 68 65 20 70 61 is used. The pa
7730: 72 61 6d 65 74 65 72 73 20 6d 61 79 20 62 65 20 rameters may be
7740: 61 0a 64 6f 74 74 65 64 20 6c 69 73 74 2c 20 69 a.dotted list, i
7750: 6e 20 77 68 69 63 68 20 63 61 73 65 20 65 6c 6c n which case ell
7760: 69 70 73 65 73 20 66 6f 72 20 61 20 43 20 76 61 ipses for a C va
7770: 72 69 61 64 69 63 20 61 72 65 20 69 6e 73 65 72 riadic are inser
7780: 74 65 64 20 2d 0a 74 68 65 20 61 63 74 75 61 6c ted -.the actual
7790: 20 6e 61 6d 65 20 6f 66 20 74 68 65 20 64 6f 74 name of the dot
77a0: 74 65 64 20 76 61 6c 75 65 20 69 73 20 69 67 6e ted value is ign
77b0: 6f 72 65 64 2e 0a 0a 54 79 70 65 73 20 61 72 65 ored...Types are
77c0: 20 6a 75 73 74 20 74 79 70 69 63 61 6c 6c 79 20 just typically
77d0: 6a 75 73 74 20 73 79 6d 62 6f 6c 73 2c 20 6f 72 just symbols, or
77e0: 20 6c 69 73 74 73 20 6f 66 20 73 79 6d 62 6f 6c lists of symbol
77f0: 73 20 73 75 63 68 20 61 73 0a 5c 71 7b 27 28 63 s such as.\q{'(c
7800: 6f 6e 73 74 20 63 68 61 72 29 7d 2e 20 20 41 20 onst char)}. A
7810: 63 6f 6d 70 6c 65 74 65 20 64 65 73 63 72 69 70 complete descrip
7820: 74 69 6f 6e 20 69 73 20 67 69 76 65 6e 20 62 65 tion is given be
7830: 6c 6f 77 20 69 6e 20 73 65 63 74 69 6f 6e 0a 5c low in section.\
7840: 72 65 66 7b 63 74 79 70 65 73 7d 2e 0a 0a 54 68 ref{ctypes}...Th
7850: 65 73 65 20 63 61 6e 20 61 6c 73 6f 20 61 63 63 ese can also acc
7860: 65 73 73 65 64 20 61 73 20 25 66 75 6e 20 61 6e essed as %fun an
7870: 64 20 25 70 72 6f 74 6f 74 79 70 65 20 61 74 20 d %prototype at
7880: 74 68 65 20 68 65 61 64 20 6f 66 20 61 20 6c 69 the head of a li
7890: 73 74 2e 0a 0a 5c 73 75 62 73 75 62 73 65 63 74 st...\subsubsect
78a0: 69 6f 6e 2a 7b 28 63 2d 76 61 72 20 3c 74 79 70 ion*{(c-var <typ
78b0: 65 3e 20 3c 6e 61 6d 65 3e 20 5b 3c 69 6e 69 74 e> <name> [<init
78c0: 2d 76 61 6c 75 65 3e 5d 29 7d 0a 0a 44 65 63 6c -value>])}..Decl
78d0: 61 72 65 73 20 61 6e 64 20 6f 70 74 69 6f 6e 61 ares and optiona
78e0: 6c 6c 79 20 69 6e 69 74 69 61 6c 69 7a 65 73 20 lly initializes
78f0: 61 20 76 61 72 69 61 62 6c 65 2e 20 20 41 6c 73 a variable. Als
7900: 6f 20 61 63 63 65 73 73 65 64 20 61 73 20 25 76 o accessed as %v
7910: 61 72 0a 61 74 20 74 68 65 20 68 65 61 64 20 6f ar.at the head o
7920: 66 20 61 20 6c 69 73 74 2e 0a 0a 5c 73 75 62 73 f a list...\subs
7930: 75 62 73 65 63 74 69 6f 6e 2a 7b 28 63 2d 62 65 ubsection*{(c-be
7940: 67 69 6e 20 3c 65 78 70 72 3e 20 2e 2e 2e 29 7d gin <expr> ...)}
7950: 0a 0a 4f 75 74 70 75 74 73 20 65 61 63 68 20 6f ..Outputs each o
7960: 66 20 74 68 65 20 3c 65 78 70 72 3e 73 2c 20 73 f the <expr>s, s
7970: 65 70 61 72 61 74 65 64 20 62 79 20 73 65 6d 69 eparated by semi
7980: 2d 63 6f 6c 6f 6e 73 20 69 66 20 69 6e 20 61 0a -colons if in a.
7990: 73 74 61 74 65 6d 65 6e 74 20 6f 72 20 63 6f 6d statement or com
79a0: 6d 61 73 20 69 66 20 69 6e 20 61 6e 20 65 78 70 mas if in an exp
79b0: 72 65 73 73 69 6f 6e 2e 0a 0a 5c 73 75 62 73 75 ression...\subsu
79c0: 62 73 65 63 74 69 6f 6e 2a 7b 28 63 2d 73 77 69 bsection*{(c-swi
79d0: 74 63 68 20 3c 63 6c 61 75 73 65 3e 20 2e 2e 2e tch <clause> ...
79e0: 29 7d 0a 5c 73 75 62 73 75 62 73 65 63 74 69 6f )}.\subsubsectio
79f0: 6e 2a 7b 28 63 2d 63 61 73 65 20 3c 76 61 6c 75 n*{(c-case <valu
7a00: 65 73 3e 20 3c 62 6f 64 79 3e 20 2e 2e 2e 29 7d es> <body> ...)}
7a10: 0a 5c 73 75 62 73 75 62 73 65 63 74 69 6f 6e 2a .\subsubsection*
7a20: 7b 28 63 2d 63 61 73 65 2f 66 61 6c 6c 74 68 72 {(c-case/fallthr
7a30: 6f 75 67 68 20 3c 76 61 6c 75 65 73 3e 20 3c 62 ough <values> <b
7a40: 6f 64 79 3e 20 2e 2e 2e 29 7d 0a 5c 73 75 62 73 ody> ...)}.\subs
7a50: 75 62 73 65 63 74 69 6f 6e 2a 7b 28 63 2d 64 65 ubsection*{(c-de
7a60: 66 61 75 6c 74 20 3c 62 6f 64 79 3e 20 2e 2e 2e fault <body> ...
7a70: 29 7d 0a 0a 53 77 69 74 63 68 20 73 74 61 74 65 )}..Switch state
7a80: 6d 65 6e 74 73 2e 20 20 49 6e 20 61 64 64 69 74 ments. In addit
7a90: 69 6f 6e 20 74 6f 20 75 73 69 6e 67 20 74 68 65 ion to using the
7aa0: 20 63 6c 61 75 73 65 20 66 6f 72 6d 61 74 74 65 clause formatte
7ab0: 72 73 2c 0a 63 6c 61 75 73 65 73 20 69 6e 73 69 rs,.clauses insi
7ac0: 64 65 20 61 20 73 77 69 74 63 68 20 6d 61 79 20 de a switch may
7ad0: 62 65 20 68 61 6e 64 6c 65 64 20 77 69 74 68 20 be handled with
7ae0: 61 20 53 63 68 65 6d 65 20 43 41 53 45 2d 6c 69 a Scheme CASE-li
7af0: 6b 65 20 6c 69 73 74 2c 0a 77 69 74 68 20 74 68 ke list,.with th
7b00: 65 20 63 61 72 20 61 20 6c 69 73 74 20 6f 66 20 e car a list of
7b10: 63 61 73 65 20 76 61 6c 75 65 73 20 61 6e 64 20 case values and
7b20: 74 68 65 20 63 64 72 20 74 68 65 20 62 6f 64 79 the cdr the body
7b30: 2e 0a 0a 5c 73 75 62 73 75 62 73 65 63 74 69 6f ...\subsubsectio
7b40: 6e 2a 7b 28 63 2d 6c 61 62 65 6c 20 3c 6e 61 6d n*{(c-label <nam
7b50: 65 3e 29 7d 0a 5c 73 75 62 73 75 62 73 65 63 74 e>)}.\subsubsect
7b60: 69 6f 6e 2a 7b 28 63 2d 67 6f 74 6f 20 3c 6e 61 ion*{(c-goto <na
7b70: 6d 65 3e 29 7d 0a 5c 73 75 62 73 75 62 73 65 63 me>)}.\subsubsec
7b80: 74 69 6f 6e 2a 7b 28 63 2d 72 65 74 75 72 6e 20 tion*{(c-return
7b90: 5b 3c 72 65 73 75 6c 74 3e 5d 29 7d 0a 5c 73 75 [<result>])}.\su
7ba0: 62 73 75 62 73 65 63 74 69 6f 6e 2a 7b 63 2d 62 bsubsection*{c-b
7bb0: 72 65 61 6b 7d 0a 5c 73 75 62 73 75 62 73 65 63 reak}.\subsubsec
7bc0: 74 69 6f 6e 2a 7b 63 2d 63 6f 6e 74 69 6e 75 65 tion*{c-continue
7bd0: 7d 0a 0a 4d 61 6e 75 61 6c 20 6c 61 62 65 6c 73 }..Manual labels
7be0: 20 61 6e 64 20 6a 75 6d 70 73 2e 20 20 4c 61 62 and jumps. Lab
7bf0: 65 6c 73 20 63 61 6e 20 61 6c 73 6f 20 62 65 20 els can also be
7c00: 61 63 63 65 73 73 65 64 20 61 73 20 61 20 6c 69 accessed as a li
7c10: 73 74 0a 62 65 67 69 6e 6e 69 6e 67 20 77 69 74 st.beginning wit
7c20: 68 20 61 20 63 6f 6c 6f 6e 2c 20 65 2e 67 2e 20 h a colon, e.g.
7c30: 5c 71 7b 27 28 3a 20 6c 61 62 65 6c 31 29 7d 2e \q{'(: label1)}.
7c40: 0a 0a 5c 73 75 62 73 75 62 73 65 63 74 69 6f 6e ..\subsubsection
7c50: 2a 7b 28 63 2d 63 6f 6e 73 74 20 3c 65 78 70 72 *{(c-const <expr
7c60: 3e 29 7d 0a 5c 73 75 62 73 75 62 73 65 63 74 69 >)}.\subsubsecti
7c70: 6f 6e 2a 7b 28 63 2d 73 74 61 74 69 63 20 3c 65 on*{(c-static <e
7c80: 78 70 72 3e 29 7d 0a 5c 73 75 62 73 75 62 73 65 xpr>)}.\subsubse
7c90: 63 74 69 6f 6e 2a 7b 28 63 2d 76 6f 6c 61 74 69 ction*{(c-volati
7ca0: 6c 65 20 3c 65 78 70 72 3e 29 7d 0a 5c 73 75 62 le <expr>)}.\sub
7cb0: 73 75 62 73 65 63 74 69 6f 6e 2a 7b 28 63 2d 72 subsection*{(c-r
7cc0: 65 73 74 72 69 63 74 20 3c 65 78 70 72 3e 29 7d estrict <expr>)}
7cd0: 0a 5c 73 75 62 73 75 62 73 65 63 74 69 6f 6e 2a .\subsubsection*
7ce0: 7b 28 63 2d 72 65 67 69 73 74 65 72 20 3c 65 78 {(c-register <ex
7cf0: 70 72 3e 29 7d 0a 5c 73 75 62 73 75 62 73 65 63 pr>)}.\subsubsec
7d00: 74 69 6f 6e 2a 7b 28 63 2d 61 75 74 6f 20 3c 65 tion*{(c-auto <e
7d10: 78 70 72 3e 29 7d 0a 5c 73 75 62 73 75 62 73 65 xpr>)}.\subsubse
7d20: 63 74 69 6f 6e 2a 7b 28 63 2d 69 6e 6c 69 6e 65 ction*{(c-inline
7d30: 20 3c 65 78 70 72 3e 29 7d 0a 5c 73 75 62 73 75 <expr>)}.\subsu
7d40: 62 73 65 63 74 69 6f 6e 2a 7b 28 63 2d 65 78 74 bsection*{(c-ext
7d50: 65 72 6e 20 3c 65 78 70 72 3e 29 7d 0a 0a 44 65 ern <expr>)}..De
7d60: 63 6c 61 72 61 74 69 6f 6e 20 6d 6f 64 69 66 69 claration modifi
7d70: 65 72 73 2e 20 20 4d 61 79 20 62 65 20 6e 65 73 ers. May be nes
7d80: 74 65 64 2e 0a 0a 5c 73 75 62 73 75 62 73 65 63 ted...\subsubsec
7d90: 74 69 6f 6e 2a 7b 28 63 2d 65 78 74 65 72 6e 2f tion*{(c-extern/
7da0: 43 20 3c 62 6f 64 79 3e 20 2e 2e 2e 29 7d 0a 0a C <body> ...)}..
7db0: 57 72 61 70 73 20 62 6f 64 79 20 69 6e 20 61 6e Wraps body in an
7dc0: 20 65 78 74 65 72 6e 20 22 43 22 20 7b 20 2e 2e extern "C" { ..
7dd0: 2e 20 7d 20 66 6f 72 20 75 73 65 20 77 69 74 68 . } for use with
7de0: 20 43 2b 2b 2e 0a 0a 5c 73 75 62 73 75 62 73 65 C++...\subsubse
7df0: 63 74 69 6f 6e 2a 7b 28 63 2d 63 61 73 74 20 3c ction*{(c-cast <
7e00: 74 79 70 65 3e 20 3c 65 78 70 72 3e 29 7d 0a 0a type> <expr>)}..
7e10: 43 61 73 74 73 20 61 6e 20 65 78 70 72 65 73 73 Casts an express
7e20: 69 6f 6e 20 74 6f 20 61 20 74 79 70 65 2e 20 20 ion to a type.
7e30: 41 6c 73 6f 20 25 63 61 73 74 20 61 74 20 74 68 Also %cast at th
7e40: 65 20 68 65 61 64 20 6f 66 20 61 20 6c 69 73 74 e head of a list
7e50: 2e 0a 0a 5c 73 75 62 73 75 62 73 65 63 74 69 6f ...\subsubsectio
7e60: 6e 2a 7b 28 63 2d 74 79 70 65 64 65 66 20 3c 74 n*{(c-typedef <t
7e70: 79 70 65 3e 20 3c 6e 65 77 2d 6e 61 6d 65 3e 20 ype> <new-name>
7e80: 2e 2e 2e 29 7d 0a 0a 43 72 65 61 74 65 73 20 61 ...)}..Creates a
7e90: 20 6e 65 77 20 74 79 70 65 20 64 65 66 69 6e 69 new type defini
7ea0: 74 69 6f 6e 20 77 69 74 68 20 6f 6e 65 20 6f 72 tion with one or
7eb0: 20 6d 6f 72 65 20 6e 61 6d 65 73 2e 0a 0a 5c 73 more names...\s
7ec0: 75 62 73 75 62 73 65 63 74 69 6f 6e 2a 7b 28 63 ubsubsection*{(c
7ed0: 2d 73 74 72 75 63 74 20 5b 3c 6e 61 6d 65 3e 5d -struct [<name>]
7ee0: 20 3c 66 69 65 6c 64 2d 6c 69 73 74 3e 20 5b 3c <field-list> [<
7ef0: 61 74 74 72 69 62 75 74 65 73 3e 5d 29 7d 0a 5c attributes>])}.\
7f00: 73 75 62 73 75 62 73 65 63 74 69 6f 6e 2a 7b 28 subsubsection*{(
7f10: 63 2d 75 6e 69 6f 6e 20 5b 3c 6e 61 6d 65 3e 5d c-union [<name>]
7f20: 20 3c 66 69 65 6c 64 2d 6c 69 73 74 3e 20 5b 3c <field-list> [<
7f30: 61 74 74 72 69 62 75 74 65 73 3e 5d 29 7d 0a 5c attributes>])}.\
7f40: 73 75 62 73 75 62 73 65 63 74 69 6f 6e 2a 7b 28 subsubsection*{(
7f50: 63 2d 63 6c 61 73 73 20 5b 3c 6e 61 6d 65 3e 5d c-class [<name>]
7f60: 20 3c 66 69 65 6c 64 2d 6c 69 73 74 3e 20 5b 3c <field-list> [<
7f70: 61 74 74 72 69 62 75 74 65 73 3e 5d 29 7d 0a 5c attributes>])}.\
7f80: 73 75 62 73 75 62 73 65 63 74 69 6f 6e 2a 7b 28 subsubsection*{(
7f90: 63 2d 61 74 74 72 69 62 75 74 65 20 3c 76 61 6c c-attribute <val
7fa0: 75 65 73 3e 20 2e 2e 2e 29 7d 0a 0a 43 6f 6d 70 ues> ...)}..Comp
7fb0: 6f 73 69 74 65 20 74 79 70 65 20 63 6f 6e 73 74 osite type const
7fc0: 72 75 63 74 6f 72 73 2e 20 20 41 74 74 72 69 62 ructors. Attrib
7fd0: 75 74 65 73 20 6d 61 79 20 62 65 20 61 63 63 65 utes may be acce
7fe0: 73 73 65 64 20 61 73 0a 25 61 74 74 72 69 62 75 ssed as.%attribu
7ff0: 74 65 20 61 74 20 74 68 65 20 68 65 61 64 20 6f te at the head o
8000: 66 20 61 20 6c 69 73 74 2e 0a 0a 5c 71 7b 0a 20 f a list...\q{.
8010: 20 28 66 6d 74 20 23 66 20 28 63 2d 73 74 72 75 (fmt #f (c-stru
8020: 63 74 20 27 65 6d 70 6c 6f 79 65 65 0a 20 20 20 ct 'employee.
8030: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
8040: 20 20 20 27 28 28 73 68 6f 72 74 20 61 67 65 29 '((short age)
8050: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
8060: 20 20 20 20 20 20 20 20 20 28 28 63 68 61 72 20 ((char
8070: 2a 29 20 6e 61 6d 65 29 0a 20 20 20 20 20 20 20 *) name).
8080: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
8090: 20 28 28 73 74 72 75 63 74 20 28 79 65 61 72 20 ((struct (year
80a0: 6d 6f 6e 74 68 20 64 61 79 29 29 20 64 6f 62 29 month day)) dob)
80b0: 29 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ).
80c0: 20 20 20 20 20 20 20 20 28 63 2d 61 74 74 72 69 (c-attri
80d0: 62 75 74 65 20 27 70 61 63 6b 65 64 29 29 29 0a bute 'packed))).
80e0: 7d 0a 0a 5c 70 7b 0a 20 20 73 74 72 75 63 74 20 }..\p{. struct
80f0: 65 6d 70 6c 6f 79 65 65 20 7b 0a 20 20 20 20 20 employee {.
8100: 20 73 68 6f 72 74 20 61 67 65 3b 0a 20 20 20 20 short age;.
8110: 20 20 63 68 61 72 2a 20 6e 61 6d 65 3b 0a 20 20 char* name;.
8120: 20 20 20 20 73 74 72 75 63 74 20 7b 0a 20 20 20 struct {.
8130: 20 20 20 20 20 20 20 69 6e 74 20 79 65 61 72 3b int year;
8140: 0a 20 20 20 20 20 20 20 20 20 20 69 6e 74 20 6d . int m
8150: 6f 6e 74 68 3b 0a 20 20 20 20 20 20 20 20 20 20 onth;.
8160: 69 6e 74 20 64 61 79 3b 0a 20 20 20 20 20 20 7d int day;. }
8170: 20 64 6f 62 3b 0a 20 20 7d 20 5f 5f 61 74 74 72 dob;. } __attr
8180: 69 62 75 74 65 5f 5f 20 28 28 70 61 63 6b 65 64 ibute__ ((packed
8190: 29 29 3b 0a 7d 0a 0a 5c 73 75 62 73 75 62 73 65 ));.}..\subsubse
81a0: 63 74 69 6f 6e 2a 7b 28 63 2d 65 6e 75 6d 20 5b ction*{(c-enum [
81b0: 3c 6e 61 6d 65 3e 5d 20 3c 65 6e 75 6d 2d 6c 69 <name>] <enum-li
81c0: 73 74 3e 29 7d 0a 0a 45 6e 75 6d 65 72 61 74 65 st>)}..Enumerate
81d0: 64 20 74 79 70 65 73 2e 20 20 5c 71 7b 3c 65 6e d types. \q{<en
81e0: 75 6d 2d 6c 69 73 74 3e 7d 20 6d 61 79 20 62 65 um-list>} may be
81f0: 20 73 74 72 69 6e 67 73 2c 20 73 79 6d 62 6f 6c strings, symbol
8200: 73 2c 20 6f 72 20 6c 69 73 74 73 20 6f 66 0a 73 s, or lists of.s
8210: 74 72 69 6e 67 20 6f 72 20 73 79 6d 62 6f 6c 20 tring or symbol
8220: 66 6f 6c 6c 6f 77 65 64 20 62 79 20 74 68 65 20 followed by the
8230: 65 6e 75 6d 27 73 20 76 61 6c 75 65 2e 0a 0a 5c enum's value...\
8240: 73 75 62 73 75 62 73 65 63 74 69 6f 6e 2a 7b 28 subsubsection*{(
8250: 63 2d 63 6f 6d 6d 65 6e 74 20 3c 66 6f 72 6d 61 c-comment <forma
8260: 74 74 65 72 3e 20 2e 2e 2e 29 7d 0a 0a 4f 75 74 tter> ...)}..Out
8270: 70 75 74 73 20 74 68 65 20 5c 71 7b 3c 66 6f 72 puts the \q{<for
8280: 6d 61 74 74 65 72 3e 7d 73 20 77 72 61 70 70 65 matter>}s wrappe
8290: 64 20 69 6e 20 43 27 73 20 2f 2a 20 2e 2e 2e 20 d in C's /* ...
82a0: 2a 2f 20 63 6f 6d 6d 65 6e 74 2e 20 20 50 72 6f */ comment. Pro
82b0: 70 65 72 6c 79 0a 65 73 63 61 70 65 73 20 6e 65 perly.escapes ne
82c0: 73 74 65 64 20 63 6f 6d 6d 65 6e 74 73 20 69 6e sted comments in
82d0: 73 69 64 65 20 69 6e 20 61 6e 20 45 6d 61 63 73 side in an Emacs
82e0: 2d 66 72 69 65 6e 64 6c 79 20 73 74 79 6c 65 2e -friendly style.
82f0: 0a 0a 5c 73 75 62 73 65 63 74 69 6f 6e 7b 43 20 ..\subsection{C
8300: 50 72 65 70 72 6f 63 65 73 73 6f 72 20 46 6f 72 Preprocessor For
8310: 6d 61 74 74 65 72 20 49 6e 64 65 78 7d 0a 0a 5c matter Index}..\
8320: 73 75 62 73 75 62 73 65 63 74 69 6f 6e 2a 7b 28 subsubsection*{(
8330: 63 70 70 2d 69 6e 63 6c 75 64 65 20 3c 66 69 6c cpp-include <fil
8340: 65 3e 29 7d 0a 0a 49 66 20 66 69 6c 65 20 69 73 e>)}..If file is
8350: 20 61 20 73 74 72 69 6e 67 2c 20 6f 75 74 70 75 a string, outpu
8360: 74 73 20 69 6e 20 69 74 20 22 71 75 6f 74 65 73 ts in it "quotes
8370: 22 2c 20 6f 74 68 65 72 77 69 73 65 20 28 61 73 ", otherwise (as
8380: 20 61 20 73 79 6d 62 6f 6c 0a 6f 72 20 61 72 62 a symbol.or arb
8390: 69 74 72 61 72 79 20 66 6f 72 6d 61 74 74 65 72 itrary formatter
83a0: 29 20 69 74 20 6f 75 74 70 75 74 73 20 69 74 20 ) it outputs it
83b0: 69 6e 20 62 72 61 63 6b 65 74 73 2e 0a 0a 20 20 in brackets...
83c0: 5c 71 7b 28 66 6d 74 20 23 66 20 28 63 70 70 2d \q{(fmt #f (cpp-
83d0: 69 6e 63 6c 75 64 65 20 27 73 74 64 69 6f 2e 68 include 'stdio.h
83e0: 29 29 7d 0a 0a 20 20 5c 71 7b 3d 3e 20 22 23 69 ))}.. \q{=> "#i
83f0: 6e 63 6c 75 64 65 20 3c 73 74 64 69 6f 2e 68 3e nclude <stdio.h>
8400: 5c 6e 22 7d 0a 0a 20 20 5c 71 7b 28 66 6d 74 20 \n"}.. \q{(fmt
8410: 23 66 20 28 63 70 70 2d 69 6e 63 6c 75 64 65 20 #f (cpp-include
8420: 22 63 6f 6e 66 69 67 2e 68 22 29 29 7d 0a 0a 20 "config.h"))}..
8430: 20 5c 71 7b 3d 3e 20 22 23 69 6e 63 6c 75 64 65 \q{=> "#include
8440: 20 5c 22 63 6f 6e 66 69 67 2e 68 5c 22 5c 6e 22 \"config.h\"\n"
8450: 7d 0a 0a 5c 73 75 62 73 75 62 73 65 63 74 69 6f }..\subsubsectio
8460: 6e 2a 7b 28 63 70 70 2d 64 65 66 69 6e 65 20 3c n*{(cpp-define <
8470: 6d 61 63 72 6f 3e 20 5b 3c 76 61 6c 75 65 3e 5d macro> [<value>]
8480: 29 7d 0a 0a 44 65 66 69 6e 65 73 20 61 20 70 72 )}..Defines a pr
8490: 65 70 72 6f 63 65 73 73 6f 72 20 6d 61 63 72 6f eprocessor macro
84a0: 2c 20 77 68 69 63 68 20 6d 61 79 20 62 65 20 6a , which may be j
84b0: 75 73 74 20 61 20 6e 61 6d 65 20 6f 72 20 61 20 ust a name or a
84c0: 6c 69 73 74 20 6f 66 0a 6e 61 6d 65 20 61 6e 64 list of.name and
84d0: 20 70 61 72 61 6d 65 74 65 72 73 2e 20 20 50 72 parameters. Pr
84e0: 6f 70 65 72 6c 79 20 77 72 61 70 73 20 74 68 65 operly wraps the
84f0: 20 76 61 6c 75 65 20 69 6e 20 70 61 72 65 6e 74 value in parent
8500: 68 65 73 69 73 20 61 6e 64 0a 65 73 63 61 70 65 hesis and.escape
8510: 73 20 6e 65 77 6c 69 6e 65 73 2e 20 20 41 20 64 s newlines. A d
8520: 6f 74 74 65 64 20 70 61 72 61 6d 65 74 65 72 20 otted parameter
8530: 6c 69 73 74 20 77 69 6c 6c 20 75 73 65 20 74 68 list will use th
8540: 65 20 43 39 39 20 76 61 72 69 61 64 69 63 0a 6d e C99 variadic.m
8550: 61 63 72 6f 20 73 79 6e 74 61 78 2c 20 61 6e 64 acro syntax, and
8560: 20 77 69 6c 6c 20 61 6c 73 6f 20 73 75 62 73 74 will also subst
8570: 69 74 75 74 65 20 61 6e 79 20 72 65 66 65 72 65 itute any refere
8580: 6e 63 65 73 20 74 6f 20 74 68 65 20 64 6f 74 74 nces to the dott
8590: 65 64 0a 6e 61 6d 65 20 77 69 74 68 20 5c 70 7b ed.name with \p{
85a0: 5f 5f 56 41 5f 41 52 47 53 5f 5f 7d 3a 0a 0a 20 __VA_ARGS__}:..
85b0: 20 5c 71 7b 28 66 6d 74 20 23 74 20 28 63 70 70 \q{(fmt #t (cpp
85c0: 2d 64 65 66 69 6e 65 20 27 28 65 70 72 69 6e 74 -define '(eprint
85d0: 66 20 2e 20 61 72 67 73 29 20 27 28 66 70 72 69 f . args) '(fpri
85e0: 6e 74 66 20 73 74 64 65 72 72 20 61 72 67 73 29 ntf stderr args)
85f0: 29 29 7d 0a 0a 5c 70 7b 0a 20 20 23 64 65 66 69 ))}..\p{. #defi
8600: 6e 65 20 65 70 72 69 6e 74 66 28 2e 2e 2e 29 20 ne eprintf(...)
8610: 28 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c (fprintf(stderr,
8620: 20 5f 5f 56 41 5f 41 52 47 53 5f 5f 29 29 0a 7d __VA_ARGS__)).}
8630: 0a 0a 5c 73 75 62 73 75 62 73 65 63 74 69 6f 6e ..\subsubsection
8640: 2a 7b 28 63 70 70 2d 69 66 20 3c 63 6f 6e 64 69 *{(cpp-if <condi
8650: 74 69 6f 6e 3e 20 3c 70 61 73 73 3e 20 5b 3c 66 tion> <pass> [<f
8660: 61 69 6c 3e 20 2e 2e 2e 5d 29 7d 0a 5c 73 75 62 ail> ...])}.\sub
8670: 73 75 62 73 65 63 74 69 6f 6e 2a 7b 28 63 70 70 subsection*{(cpp
8680: 2d 69 66 64 65 66 20 3c 63 6f 6e 64 69 74 69 6f -ifdef <conditio
8690: 6e 3e 20 3c 70 61 73 73 3e 20 5b 3c 66 61 69 6c n> <pass> [<fail
86a0: 3e 20 2e 2e 2e 5d 29 7d 0a 5c 73 75 62 73 75 62 > ...])}.\subsub
86b0: 73 65 63 74 69 6f 6e 2a 7b 28 63 70 70 2d 69 66 section*{(cpp-if
86c0: 6e 64 65 66 20 3c 63 6f 6e 64 69 74 69 6f 6e 3e ndef <condition>
86d0: 20 3c 70 61 73 73 3e 20 5b 3c 66 61 69 6c 3e 20 <pass> [<fail>
86e0: 2e 2e 2e 5d 29 7d 0a 5c 73 75 62 73 75 62 73 65 ...])}.\subsubse
86f0: 63 74 69 6f 6e 2a 7b 28 63 70 70 2d 65 6c 69 66 ction*{(cpp-elif
8700: 20 3c 63 6f 6e 64 69 74 69 6f 6e 3e 20 3c 70 61 <condition> <pa
8710: 73 73 3e 20 5b 3c 66 61 69 6c 3e 20 2e 2e 2e 5d ss> [<fail> ...]
8720: 29 7d 0a 5c 73 75 62 73 75 62 73 65 63 74 69 6f )}.\subsubsectio
8730: 6e 2a 7b 28 63 70 70 2d 65 6c 73 65 20 3c 62 6f n*{(cpp-else <bo
8740: 64 79 3e 20 2e 2e 2e 29 7d 0a 0a 43 6f 6e 64 69 dy> ...)}..Condi
8750: 74 69 6f 6e 61 6c 20 63 6f 6d 70 69 6c 61 74 69 tional compilati
8760: 6f 6e 2e 0a 0a 5c 73 75 62 73 75 62 73 65 63 74 on...\subsubsect
8770: 69 6f 6e 2a 7b 28 63 70 70 2d 6c 69 6e 65 20 3c ion*{(cpp-line <
8780: 6e 75 6d 3e 20 5b 3c 66 69 6c 65 3e 5d 29 7d 0a num> [<file>])}.
8790: 0a 4c 69 6e 65 20 6e 75 6d 62 65 72 20 69 6e 66 .Line number inf
87a0: 6f 72 6d 61 74 69 6f 6e 2e 0a 0a 5c 73 75 62 73 ormation...\subs
87b0: 75 62 73 65 63 74 69 6f 6e 2a 7b 28 63 70 70 2d ubsection*{(cpp-
87c0: 70 72 61 67 6d 61 20 3c 61 72 67 73 3e 20 2e 2e pragma <args> ..
87d0: 2e 29 7d 0a 5c 73 75 62 73 75 62 73 65 63 74 69 .)}.\subsubsecti
87e0: 6f 6e 2a 7b 28 63 70 70 2d 65 72 72 6f 72 20 3c on*{(cpp-error <
87f0: 61 72 67 73 3e 20 2e 2e 2e 29 7d 0a 5c 73 75 62 args> ...)}.\sub
8800: 73 75 62 73 65 63 74 69 6f 6e 2a 7b 28 63 70 70 subsection*{(cpp
8810: 2d 77 61 72 6e 69 6e 67 20 3c 61 72 67 73 3e 20 -warning <args>
8820: 2e 2e 2e 29 7d 0a 0a 41 64 64 69 74 69 6f 6e 61 ...)}..Additiona
8830: 6c 20 70 72 65 70 72 6f 63 65 73 73 6f 72 20 64 l preprocessor d
8840: 69 72 65 63 74 69 76 65 73 2e 0a 0a 5c 73 75 62 irectives...\sub
8850: 73 75 62 73 65 63 74 69 6f 6e 2a 7b 28 63 70 70 subsection*{(cpp
8860: 2d 73 74 72 69 6e 67 69 66 79 20 3c 65 78 70 72 -stringify <expr
8870: 3e 29 7d 0a 0a 53 74 72 69 6e 67 69 66 69 65 73 >)}..Stringifies
8880: 20 5c 71 7b 3c 65 78 70 72 3e 7d 20 62 79 20 70 \q{<expr>} by p
8890: 72 65 66 69 78 69 6e 67 20 74 68 65 20 23 20 6f refixing the # o
88a0: 70 65 72 61 74 6f 72 2e 0a 0a 5c 73 75 62 73 75 perator...\subsu
88b0: 62 73 65 63 74 69 6f 6e 2a 7b 28 63 70 70 2d 73 bsection*{(cpp-s
88c0: 79 6d 2d 63 61 74 20 3c 61 72 67 73 3e 20 2e 2e ym-cat <args> ..
88d0: 2e 29 7d 0a 0a 4a 6f 69 6e 73 20 74 68 65 20 5c .)}..Joins the \
88e0: 71 7b 3c 61 72 67 73 3e 7d 20 69 6e 74 6f 20 61 q{<args>} into a
88f0: 20 73 69 6e 67 6c 65 20 70 72 65 70 72 6f 63 65 single preproce
8900: 73 73 6f 72 20 74 6f 6b 65 6e 20 77 69 74 68 20 ssor token with
8910: 74 68 65 20 23 23 0a 6f 70 65 72 61 74 6f 72 2e the ##.operator.
8920: 0a 0a 5c 73 75 62 73 75 62 73 65 63 74 69 6f 6e ..\subsubsection
8930: 2a 7b 28 63 70 70 2d 77 72 61 70 2d 68 65 61 64 *{(cpp-wrap-head
8940: 65 72 20 3c 6e 61 6d 65 3e 20 3c 62 6f 64 79 3e er <name> <body>
8950: 20 2e 2e 2e 29 7d 0a 0a 57 72 61 70 20 61 6e 20 ...)}..Wrap an
8960: 65 6e 74 69 72 65 20 68 65 61 64 65 72 20 74 6f entire header to
8970: 20 6f 6e 6c 79 20 62 65 20 69 6e 63 6c 75 64 65 only be include
8980: 64 20 6f 6e 63 65 2e 0a 0a 5c 73 75 62 73 75 62 d once...\subsub
8990: 73 65 63 74 69 6f 6e 2a 7b 4f 70 65 72 61 74 6f section*{Operato
89a0: 72 73 3a 7d 0a 0a 5c 71 7b 0a 63 2b 2b 20 63 2d rs:}..\q{.c++ c-
89b0: 2d 20 63 2b 20 63 2d 20 63 2a 20 63 2f 20 63 25 - c+ c- c* c/ c%
89c0: 20 63 26 20 63 5e 20 63 7e 20 63 21 20 63 26 26 c& c^ c~ c! c&&
89d0: 20 63 3c 3c 20 63 3e 3e 20 63 3d 3d 20 63 21 3d c<< c>> c== c!=
89e0: 0a 63 3c 20 63 3e 20 63 3c 3d 20 63 3e 3d 20 63 .c< c> c<= c>= c
89f0: 3d 20 63 2b 3d 20 63 2d 3d 20 63 2a 3d 20 63 2f = c+= c-= c*= c/
8a00: 3d 20 63 25 3d 20 63 26 3d 20 63 5e 3d 20 63 3c = c%= c&= c^= c<
8a10: 3c 3d 20 63 3e 3e 3d 0a 63 2b 2b 2f 70 6f 73 74 <= c>>=.c++/post
8a20: 20 63 2d 2d 2f 70 6f 73 74 20 63 2d 6f 72 20 63 c--/post c-or c
8a30: 2d 62 69 74 2d 6f 72 20 63 2d 62 69 74 2d 6f 72 -bit-or c-bit-or
8a40: 3d 0a 7d 0a 0a 5c 73 75 62 73 65 63 74 69 6f 6e =.}..\subsection
8a50: 7b 43 20 54 79 70 65 73 7d 0a 5c 6c 61 62 65 6c {C Types}.\label
8a60: 7b 63 74 79 70 65 73 7d 0a 0a 54 79 70 69 63 61 {ctypes}..Typica
8a70: 6c 6c 79 20 61 20 74 79 70 65 20 69 73 20 6a 75 lly a type is ju
8a80: 73 74 20 61 20 73 79 6d 62 6f 6c 20 73 75 63 68 st a symbol such
8a90: 20 61 73 20 5c 71 7b 27 63 68 61 72 7d 20 6f 72 as \q{'char} or
8aa0: 20 5c 71 7b 27 69 6e 74 7d 2e 20 20 59 6f 75 0a \q{'int}. You.
8ab0: 63 61 6e 20 77 72 61 70 20 74 79 70 65 73 20 77 can wrap types w
8ac0: 69 74 68 20 6d 6f 64 69 66 69 65 72 73 20 73 75 ith modifiers su
8ad0: 63 68 20 61 73 20 5c 71 7b 63 2d 63 6f 6e 73 74 ch as \q{c-const
8ae0: 7d 2c 20 62 75 74 20 61 73 20 61 0a 63 6f 6e 76 }, but as a.conv
8af0: 65 6e 69 65 6e 63 65 20 79 6f 75 20 63 61 6e 20 enience you can
8b00: 6a 75 73 74 20 75 73 65 20 61 20 6c 69 73 74 20 just use a list
8b10: 73 75 63 68 20 61 73 20 69 6e 20 5c 71 7b 27 28 such as in \q{'(
8b20: 63 6f 6e 73 74 20 75 6e 73 69 67 6e 65 64 63 68 const unsignedch
8b30: 61 72 20 2a 29 7d 2e 0a 59 6f 75 20 63 61 6e 20 ar *)}..You can
8b40: 61 6c 73 6f 20 6e 65 73 74 20 74 68 65 73 65 20 also nest these
8b50: 6c 69 73 74 73 2c 20 73 6f 20 74 68 65 20 70 72 lists, so the pr
8b60: 65 76 69 6f 75 73 20 65 78 61 6d 70 6c 65 20 69 evious example i
8b70: 73 0a 65 71 75 69 76 61 6c 65 6e 74 20 74 6f 20 s.equivalent to
8b80: 5c 71 7b 27 28 2a 20 28 63 6f 6e 73 74 20 28 75 \q{'(* (const (u
8b90: 6e 73 69 67 6e 65 64 20 63 68 61 72 29 29 29 7d nsigned char)))}
8ba0: 2e 0a 0a 50 6f 69 6e 74 65 72 73 20 6d 61 79 20 ...Pointers may
8bb0: 62 65 20 77 72 69 74 74 65 6e 20 61 73 20 5c 71 be written as \q
8bc0: 7b 27 28 25 70 6f 69 6e 74 65 72 20 3c 74 79 70 {'(%pointer <typ
8bd0: 65 3e 29 7d 20 66 6f 72 20 72 65 61 64 61 62 69 e>)} for readabi
8be0: 6c 69 74 79 20 2d 0a 5c 71 7b 25 70 6f 69 6e 74 lity -.\q{%point
8bf0: 65 72 7d 20 69 73 20 65 78 61 63 74 6c 79 20 65 er} is exactly e
8c00: 71 75 69 76 61 6c 65 6e 74 20 74 6f 20 5c 71 7b quivalent to \q{
8c10: 2a 7d 20 69 6e 20 74 79 70 65 73 2e 0a 0a 55 6e *} in types...Un
8c20: 61 6d 65 64 20 73 74 72 75 63 74 73 2c 20 63 6c amed structs, cl
8c30: 61 73 73 65 73 2c 20 75 6e 69 6f 6e 73 20 61 6e asses, unions an
8c40: 64 20 65 6e 75 6d 73 20 6d 61 79 20 62 65 20 75 d enums may be u
8c50: 73 65 64 20 64 69 72 65 63 74 6c 79 20 61 73 0a sed directly as.
8c60: 74 79 70 65 73 2c 20 75 73 69 6e 67 20 74 68 65 types, using the
8c70: 69 72 20 72 65 73 70 65 63 74 69 76 65 20 6b 65 ir respective ke
8c80: 79 77 6f 72 64 73 20 61 74 20 74 68 65 20 68 65 ywords at the he
8c90: 61 64 20 6f 66 20 61 20 6c 69 73 74 2e 0a 0a 54 ad of a list...T
8ca0: 77 6f 20 73 70 65 63 69 61 6c 20 74 79 70 65 73 wo special types
8cb0: 20 61 72 65 20 74 68 65 20 25 61 72 72 61 79 20 are the %array
8cc0: 74 79 70 65 20 61 6e 64 20 66 75 6e 63 74 69 6f type and functio
8cd0: 6e 20 70 6f 69 6e 74 65 72 20 74 79 70 65 2e 20 n pointer type.
8ce0: 20 41 6e 0a 61 72 72 61 79 20 69 73 20 77 72 69 An.array is wri
8cf0: 74 74 65 6e 3a 0a 0a 20 20 5c 71 7b 28 25 61 72 tten:.. \q{(%ar
8d00: 72 61 79 20 3c 74 79 70 65 3e 20 5b 3c 73 69 7a ray <type> [<siz
8d10: 65 3e 5d 29 7d 0a 0a 77 68 65 72 65 20 5c 71 7b e>])}..where \q{
8d20: 3c 74 79 70 65 3e 7d 20 69 73 20 61 6e 79 20 6f <type>} is any o
8d30: 74 68 65 72 20 74 79 70 65 20 28 69 6e 63 6c 75 ther type (inclu
8d40: 64 69 6e 67 20 61 6e 6f 74 68 65 72 20 61 72 72 ding another arr
8d50: 61 79 20 6f 72 0a 66 75 6e 63 74 69 6f 6e 20 70 ay or.function p
8d60: 6f 69 6e 74 65 72 29 2c 20 61 6e 64 20 5c 71 7b ointer), and \q{
8d70: 3c 73 69 7a 65 3e 7d 2c 20 69 66 20 67 69 76 65 <size>}, if give
8d80: 6e 2c 20 77 69 6c 6c 20 70 72 69 6e 74 20 74 68 n, will print th
8d90: 65 20 61 72 72 61 79 0a 73 69 7a 65 2e 20 20 46 e array.size. F
8da0: 6f 72 20 65 78 61 6d 70 6c 65 3a 0a 0a 20 20 5c or example:.. \
8db0: 71 7b 28 63 2d 76 61 72 20 27 28 25 61 72 72 61 q{(c-var '(%arra
8dc0: 79 20 28 75 6e 73 69 67 6e 65 64 20 6c 6f 6e 67 y (unsigned long
8dd0: 29 20 53 49 5a 45 29 20 27 74 61 62 6c 65 20 27 ) SIZE) 'table '
8de0: 23 28 31 20 32 20 33 20 34 29 29 7d 0a 0a 5c 70 #(1 2 3 4))}..\p
8df0: 7b 0a 75 6e 73 69 67 6e 65 64 20 6c 6f 6e 67 20 {.unsigned long
8e00: 74 61 62 6c 65 5b 53 49 5a 45 5d 20 3d 20 7b 31 table[SIZE] = {1
8e10: 2c 20 32 2c 20 33 2c 20 34 7d 3b 0a 7d 0a 0a 41 , 2, 3, 4};.}..A
8e20: 20 66 75 6e 63 74 69 6f 6e 20 70 6f 69 6e 74 65 function pointe
8e30: 72 20 69 73 20 77 72 69 74 74 65 6e 3a 0a 0a 20 r is written:..
8e40: 20 5c 71 7b 28 25 66 75 6e 20 3c 72 65 74 75 72 \q{(%fun <retur
8e50: 6e 2d 74 79 70 65 3e 20 28 3c 70 61 72 61 6d 2d n-type> (<param-
8e60: 74 79 70 65 73 3e 20 2e 2e 2e 29 29 7d 0a 0a 46 types> ...))}..F
8e70: 6f 72 20 65 78 61 6d 70 6c 65 3a 0a 0a 20 20 5c or example:.. \
8e80: 71 7b 28 63 2d 74 79 70 65 64 65 66 20 27 28 25 q{(c-typedef '(%
8e90: 66 75 6e 20 64 6f 75 62 6c 65 20 28 64 6f 75 62 fun double (doub
8ea0: 6c 65 20 64 6f 75 62 6c 65 20 69 6e 74 29 29 20 le double int))
8eb0: 27 66 29 7d 0a 0a 5c 70 7b 0a 74 79 70 65 64 65 'f)}..\p{.typede
8ec0: 66 20 64 6f 75 62 6c 65 20 28 2a 66 29 28 64 6f f double (*f)(do
8ed0: 75 62 6c 65 2c 20 64 6f 75 62 6c 65 2c 20 69 6e uble, double, in
8ee0: 74 29 3b 0a 7d 0a 0a 57 68 65 72 65 76 65 72 20 t);.}..Wherever
8ef0: 61 20 74 79 70 65 20 69 73 20 65 78 70 65 63 74 a type is expect
8f00: 65 64 20 62 75 74 20 6e 6f 74 20 67 69 76 65 6e ed but not given
8f10: 2c 20 74 68 65 20 76 61 6c 75 65 20 6f 66 20 74 , the value of t
8f20: 68 65 0a 5c 71 7b 27 64 65 66 61 75 6c 74 2d 74 he.\q{'default-t
8f30: 79 70 65 7d 20 66 6f 72 6d 61 74 74 69 6e 67 20 ype} formatting
8f40: 73 74 61 74 65 20 76 61 72 69 61 62 6c 65 20 69 state variable i
8f50: 73 20 75 73 65 64 2e 20 20 42 79 20 64 65 66 61 s used. By defa
8f60: 75 6c 74 20 74 68 69 73 0a 69 73 20 6a 75 73 74 ult this.is just
8f70: 20 5c 71 7b 27 69 6e 74 7d 2e 0a 0a 54 79 70 65 \q{'int}...Type
8f80: 20 64 65 63 6c 61 72 61 74 69 6f 6e 73 20 77 6f declarations wo
8f90: 72 6b 20 75 6e 69 66 6f 72 6d 6c 79 20 66 6f 72 rk uniformly for
8fa0: 20 76 61 72 69 61 62 6c 65 73 20 61 6e 64 20 70 variables and p
8fb0: 61 72 61 6d 65 74 65 72 73 2c 20 61 73 20 77 65 arameters, as we
8fc0: 6c 6c 0a 66 6f 72 20 63 61 73 74 73 20 61 6e 64 ll.for casts and
8fd0: 20 74 79 70 65 64 65 66 73 2e 0a 0a 5c 73 75 62 typedefs...\sub
8fe0: 73 65 63 74 69 6f 6e 7b 43 20 61 73 20 53 2d 45 section{C as S-E
8ff0: 78 70 72 65 73 73 69 6f 6e 73 7d 0a 5c 6c 61 62 xpressions}.\lab
9000: 65 6c 7b 63 73 65 78 70 72 73 7d 0a 0a 52 61 74 el{csexprs}..Rat
9010: 68 65 72 20 74 68 61 6e 20 62 75 69 6c 64 69 6e her than buildin
9020: 67 20 66 6f 72 6d 61 74 74 69 6e 67 20 63 6c 6f g formatting clo
9030: 73 75 72 65 73 20 62 79 20 68 61 6e 64 2c 20 69 sures by hand, i
9040: 74 20 63 61 6e 20 62 65 20 6d 6f 72 65 0a 63 6f t can be more.co
9050: 6e 76 65 6e 69 65 6e 74 20 74 6f 20 6a 75 73 74 nvenient to just
9060: 20 62 75 69 6c 64 20 61 20 6e 6f 72 6d 61 6c 20 build a normal
9070: 73 2d 65 78 70 72 65 73 73 69 6f 6e 20 61 6e 64 s-expression and
9080: 20 61 73 6b 20 66 6f 72 20 69 74 20 74 6f 20 62 ask for it to b
9090: 65 0a 66 6f 72 6d 61 74 74 65 64 20 61 73 20 43 e.formatted as C
90a0: 20 63 6f 64 65 2e 20 20 54 68 69 73 20 63 61 6e code. This can
90b0: 20 62 65 20 74 68 6f 75 67 68 74 20 6f 66 20 61 be thought of a
90c0: 73 20 61 20 73 69 6d 70 6c 65 20 53 63 68 65 6d s a simple Schem
90d0: 65 2d 3e 43 0a 63 6f 6d 70 69 6c 65 72 20 77 69 e->C.compiler wi
90e0: 74 68 6f 75 74 20 61 6e 79 20 72 75 6e 74 69 6d thout any runtim
90f0: 65 20 73 75 70 70 6f 72 74 2e 0a 0a 49 6e 20 61 e support...In a
9100: 20 73 2d 65 78 70 72 65 73 73 69 6f 6e 2c 20 73 s-expression, s
9110: 74 72 69 6e 67 73 20 61 6e 64 20 63 68 61 72 61 trings and chara
9120: 63 74 65 72 73 20 61 72 65 20 70 72 69 6e 74 65 cters are printe
9130: 64 20 61 73 20 43 20 73 74 72 69 6e 67 73 20 61 d as C strings a
9140: 6e 64 0a 63 68 61 72 61 63 74 65 72 73 2c 20 62 nd.characters, b
9150: 6f 6f 6c 65 61 6e 73 20 61 72 65 20 70 72 69 6e ooleans are prin
9160: 74 65 64 20 61 73 20 30 20 6f 72 20 31 2c 20 73 ted as 0 or 1, s
9170: 79 6d 62 6f 6c 73 20 61 72 65 20 64 69 73 70 6c ymbols are displ
9180: 61 79 65 64 0a 61 73 2d 69 73 2c 20 61 6e 64 20 ayed.as-is, and
9190: 6e 75 6d 62 65 72 73 20 61 72 65 20 70 72 69 6e numbers are prin
91a0: 74 65 64 20 61 73 20 43 20 6e 75 6d 62 65 72 73 ted as C numbers
91b0: 20 28 75 73 69 6e 67 20 74 68 65 20 63 75 72 72 (using the curr
91c0: 65 6e 74 0a 66 6f 72 6d 61 74 74 69 6e 67 20 72 ent.formatting r
91d0: 61 64 69 78 20 69 66 20 73 70 65 63 69 66 69 65 adix if specifie
91e0: 64 29 2e 20 20 56 65 63 74 6f 72 73 20 61 72 65 d). Vectors are
91f0: 20 70 72 69 6e 74 65 64 20 61 73 0a 63 6f 6d 6d printed as.comm
9200: 61 2d 73 65 70 61 72 61 74 65 64 20 6c 69 73 74 a-separated list
9210: 73 20 77 72 61 70 70 65 64 20 69 6e 20 62 72 61 s wrapped in bra
9220: 63 65 73 2c 20 77 68 69 63 68 20 63 61 6e 20 62 ces, which can b
9230: 65 20 75 73 65 64 20 66 6f 72 0a 69 6e 69 74 69 e used for.initi
9240: 61 6c 69 7a 69 6e 67 20 61 72 72 61 79 73 20 6f alizing arrays o
9250: 72 20 73 74 72 75 63 74 73 2e 0a 0a 41 20 6c 69 r structs...A li
9260: 73 74 20 69 6e 64 69 63 61 74 65 73 20 61 20 43 st indicates a C
9270: 20 65 78 70 72 65 73 73 69 6f 6e 20 6f 72 20 73 expression or s
9280: 74 61 74 65 6d 65 6e 74 2e 20 20 41 6e 79 20 6f tatement. Any o
9290: 66 20 74 68 65 20 65 78 69 73 74 69 6e 67 20 43 f the existing C
92a0: 0a 6b 65 79 77 6f 72 64 73 20 63 61 6e 20 62 65 .keywords can be
92b0: 20 75 73 65 64 20 74 6f 20 70 72 65 74 74 79 2d used to pretty-
92c0: 70 72 69 6e 74 20 74 68 65 20 65 78 70 72 65 73 print the expres
92d0: 73 69 6f 6e 20 61 73 20 64 65 73 63 72 69 62 65 sion as describe
92e0: 64 20 77 69 74 68 0a 74 68 65 20 63 2d 6b 65 79 d with.the c-key
92f0: 77 6f 72 64 20 66 6f 72 6d 61 74 74 65 72 73 20 word formatters
9300: 61 62 6f 76 65 2e 20 20 54 68 75 73 2c 20 74 68 above. Thus, th
9310: 65 20 65 78 61 6d 70 6c 65 20 61 62 6f 76 65 0a e example above.
9320: 0a 20 20 5c 71 7b 28 66 6d 74 20 23 74 20 28 63 . \q{(fmt #t (c
9330: 2d 69 66 20 28 63 2d 69 66 20 31 20 32 20 33 29 -if (c-if 1 2 3)
9340: 20 34 20 35 29 29 7d 0a 0a 63 6f 75 6c 64 20 61 4 5))}..could a
9350: 6c 73 6f 20 62 65 20 77 72 69 74 74 65 6e 0a 0a lso be written..
9360: 20 20 5c 71 7b 28 66 6d 74 20 23 74 20 28 63 2d \q{(fmt #t (c-
9370: 65 78 70 72 20 27 28 69 66 20 28 69 66 20 31 20 expr '(if (if 1
9380: 32 20 33 29 20 34 20 35 29 29 29 7d 0a 0a 43 20 2 3) 4 5)))}..C
9390: 63 6f 6e 73 74 72 75 63 74 73 20 74 68 61 74 20 constructs that
93a0: 61 72 65 20 64 65 70 65 6e 64 65 6e 74 20 6f 6e are dependent on
93b0: 20 74 68 65 20 75 6e 64 65 72 6c 79 69 6e 67 20 the underlying
93c0: 73 79 6e 74 61 78 20 61 6e 64 20 68 61 76 65 20 syntax and have
93d0: 6e 6f 0a 6b 65 79 77 6f 72 64 20 61 72 65 20 77 no.keyword are w
93e0: 72 69 74 74 65 6e 20 77 69 74 68 20 61 20 25 20 ritten with a %
93f0: 70 72 65 66 69 78 20 28 5c 71 7b 25 66 75 6e 7d prefix (\q{%fun}
9400: 2c 20 5c 71 7b 25 76 61 72 7d 2c 20 5c 71 7b 25 , \q{%var}, \q{%
9410: 70 6f 69 6e 74 65 72 7d 2c 0a 5c 71 7b 25 61 72 pointer},.\q{%ar
9420: 72 61 79 7d 2c 20 5c 71 7b 25 63 61 73 74 7d 29 ray}, \q{%cast})
9430: 2c 20 69 6e 63 6c 75 64 69 6e 67 20 43 20 70 72 , including C pr
9440: 65 70 72 6f 63 65 73 73 6f 72 20 63 6f 6e 73 74 eprocessor const
9450: 72 75 63 74 73 0a 28 5c 71 7b 25 69 6e 63 6c 75 ructs.(\q{%inclu
9460: 64 65 7d 2c 20 5c 71 7b 25 64 65 66 69 6e 65 7d de}, \q{%define}
9470: 2c 20 5c 71 7b 25 70 72 61 67 6d 61 7d 2c 20 5c , \q{%pragma}, \
9480: 71 7b 25 65 72 72 6f 72 7d 2c 20 5c 71 7b 25 77 q{%error}, \q{%w
9490: 61 72 6e 69 6e 67 7d 2c 0a 5c 71 7b 25 69 66 7d arning},.\q{%if}
94a0: 2c 20 5c 71 7b 25 69 66 64 65 66 7d 2c 20 5c 71 , \q{%ifdef}, \q
94b0: 7b 25 69 66 6e 64 65 66 7d 2c 20 5c 71 7b 25 65 {%ifndef}, \q{%e
94c0: 6c 69 66 7d 29 2e 20 20 4c 61 62 65 6c 73 20 61 lif}). Labels a
94d0: 72 65 20 77 72 69 74 74 65 6e 20 61 73 0a 5c 71 re written as.\q
94e0: 7b 28 3a 20 3c 6c 61 62 65 6c 2d 6e 61 6d 65 3e {(: <label-name>
94f0: 29 7d 2e 20 20 59 6f 75 20 63 61 6e 20 77 72 69 )}. You can wri
9500: 74 65 20 61 20 73 65 71 75 65 6e 63 65 20 61 73 te a sequence as
9510: 20 5c 71 7b 28 25 62 65 67 69 6e 20 3c 65 78 70 \q{(%begin <exp
9520: 72 3e 0a 2e 2e 2e 29 7d 2e 0a 0a 46 6f 72 20 65 r>....)}...For e
9530: 78 61 6d 70 6c 65 2c 20 74 68 65 20 66 6f 6c 6c xample, the foll
9540: 6f 77 69 6e 67 20 64 65 66 69 6e 69 74 69 6f 6e owing definition
9550: 20 6f 66 20 74 68 65 20 66 69 62 6f 6e 61 63 63 of the fibonacc
9560: 69 20 73 65 71 75 65 6e 63 65 2c 20 77 68 69 63 i sequence, whic
9570: 68 0a 61 70 61 72 74 20 66 72 6f 6d 20 74 68 65 h.apart from the
9580: 20 72 65 74 75 72 6e 20 74 79 70 65 20 6f 66 20 return type of
9590: 5c 71 7b 23 66 7d 20 6c 6f 6f 6b 73 20 6c 69 6b \q{#f} looks lik
95a0: 65 20 61 20 4c 69 73 70 20 64 65 66 69 6e 69 74 e a Lisp definit
95b0: 69 6f 6e 3a 0a 0a 20 20 5c 71 7b 28 66 6d 74 20 ion:.. \q{(fmt
95c0: 23 74 20 28 63 2d 65 78 70 72 20 27 28 25 66 75 #t (c-expr '(%fu
95d0: 6e 20 23 66 20 66 69 62 20 28 6e 29 0a 20 20 20 n #f fib (n).
95e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
95f0: 20 20 20 20 20 20 28 69 66 20 28 3c 3d 20 6e 20 (if (<= n
9600: 31 29 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 1).
9610: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
9620: 31 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 1.
9630: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 28 (
9640: 2b 20 28 66 69 62 20 28 2d 20 6e 20 31 29 29 20 + (fib (- n 1))
9650: 28 66 69 62 20 28 2d 20 6e 20 32 29 29 29 29 29 (fib (- n 2)))))
9660: 29 29 7d 0a 0a 70 72 69 6e 74 73 20 74 68 65 20 ))}..prints the
9670: 77 6f 72 6b 69 6e 67 20 43 20 64 65 66 69 6e 69 working C defini
9680: 74 69 6f 6e 3a 0a 0a 5c 70 7b 0a 69 6e 74 20 66 tion:..\p{.int f
9690: 69 62 20 28 69 6e 74 20 6e 29 20 7b 0a 20 20 20 ib (int n) {.
96a0: 20 69 66 20 28 6e 20 3c 3d 20 31 29 20 7b 0a 20 if (n <= 1) {.
96b0: 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 31 3b return 1;
96c0: 0a 20 20 20 20 7d 20 65 6c 73 65 20 7b 0a 20 20 . } else {.
96d0: 20 20 20 20 20 20 72 65 74 75 72 6e 20 66 69 62 return fib
96e0: 28 28 6e 20 2d 20 31 29 29 20 2b 20 66 69 62 28 ((n - 1)) + fib(
96f0: 28 6e 20 2d 20 32 29 29 3b 0a 20 20 20 20 7d 0a (n - 2));. }.
9700: 7d 0a 7d 0a 0a 5c 73 65 63 74 69 6f 6e 7b 4a 61 }.}..\section{Ja
9710: 76 61 53 63 72 69 70 74 20 46 6f 72 6d 61 74 74 vaScript Formatt
9720: 69 6e 67 7d 0a 0a 54 68 65 20 65 78 70 65 72 69 ing}..The experi
9730: 6d 65 6e 74 61 6c 20 66 6d 74 2d 6a 73 20 6c 69 mental fmt-js li
9740: 62 72 61 72 79 20 65 78 74 65 6e 64 73 20 74 68 brary extends th
9750: 65 20 66 6d 74 2d 63 20 6c 69 62 72 61 72 79 20 e fmt-c library
9760: 77 69 74 68 0a 66 75 6e 63 74 69 6f 6e 61 6c 69 with.functionali
9770: 74 79 20 66 6f 72 20 66 6f 72 6d 61 74 74 69 6e ty for formattin
9780: 67 20 4a 61 76 61 53 63 72 69 70 74 20 63 6f 64 g JavaScript cod
9790: 65 2e 0a 0a 5c 73 75 62 73 75 62 73 65 63 74 69 e...\subsubsecti
97a0: 6f 6e 2a 7b 28 6a 73 2d 65 78 70 72 20 78 29 7d on*{(js-expr x)}
97b0: 0a 0a 46 6f 72 6d 61 74 73 20 61 20 4a 61 76 61 ..Formats a Java
97c0: 53 63 72 69 70 74 20 65 78 70 72 65 73 73 69 6f Script expressio
97d0: 6e 20 73 69 6d 69 6c 61 72 6c 79 20 74 6f 20 5c n similarly to \
97e0: 71 7b 63 2d 65 78 70 72 7d 2e 20 20 49 6e 73 69 q{c-expr}. Insi
97f0: 64 65 20 61 0a 5c 71 7b 6a 73 2d 65 78 70 72 7d de a.\q{js-expr}
9800: 20 66 6f 72 6d 61 74 74 65 72 2c 20 79 6f 75 20 formatter, you
9810: 63 61 6e 20 75 73 65 20 74 68 65 20 6e 6f 72 6d can use the norm
9820: 61 6c 20 5c 71 7b 63 2d 7d 20 70 72 65 66 69 78 al \q{c-} prefix
9830: 65 64 0a 66 6f 72 6d 61 74 74 65 72 73 20 64 65 ed.formatters de
9840: 73 63 72 69 62 65 64 20 69 6e 20 74 68 65 20 70 scribed in the p
9850: 72 65 76 69 6f 75 73 20 73 65 63 74 69 6f 6e 2c revious section,
9860: 20 61 6e 64 20 74 68 65 79 20 77 69 6c 6c 20 66 and they will f
9870: 6f 72 6d 61 74 0a 61 70 70 72 6f 70 72 69 61 74 ormat.appropriat
9880: 65 6c 79 20 66 6f 72 20 4a 61 76 61 53 63 72 69 ely for JavaScri
9890: 70 74 2e 0a 0a 43 75 72 72 65 6e 74 6c 79 20 65 pt...Currently e
98a0: 78 70 72 65 73 73 69 6f 6e 73 20 77 69 6c 6c 20 xpressions will
98b0: 61 6c 6c 20 62 65 20 74 65 72 6d 69 6e 61 74 65 all be terminate
98c0: 64 20 77 69 74 68 20 61 20 73 65 6d 69 2d 63 6f d with a semi-co
98d0: 6c 6f 6e 2c 20 62 75 74 0a 74 68 61 74 20 77 69 lon, but.that wi
98e0: 6c 6c 20 62 65 20 6d 61 64 65 20 6f 70 74 69 6f ll be made optio
98f0: 6e 61 6c 20 69 6e 20 61 20 6c 61 74 65 72 20 72 nal in a later r
9900: 65 6c 65 61 73 65 2e 0a 0a 5c 73 75 62 73 75 62 elease...\subsub
9910: 73 65 63 74 69 6f 6e 2a 7b 28 6a 73 2d 66 75 6e section*{(js-fun
9920: 63 74 69 6f 6e 20 5b 3c 6e 61 6d 65 3e 5d 20 28 ction [<name>] (
9930: 3c 70 61 72 61 6d 73 3e 29 20 3c 62 6f 64 79 3e <params>) <body>
9940: 20 2e 2e 2e 29 7d 0a 0a 44 65 66 69 6e 65 73 20 ...)}..Defines
9950: 61 20 66 75 6e 63 74 69 6f 6e 20 28 61 6e 6f 6e a function (anon
9960: 79 6d 6f 75 73 6c 79 20 69 66 20 6e 6f 20 6e 61 ymously if no na
9970: 6d 65 20 69 73 20 70 72 6f 76 69 64 65 64 29 2e me is provided).
9980: 0a 0a 5c 73 75 62 73 75 62 73 65 63 74 69 6f 6e ..\subsubsection
9990: 2a 7b 28 6a 73 2d 76 61 72 20 3c 6e 61 6d 65 3e *{(js-var <name>
99a0: 20 5b 3c 69 6e 69 74 2d 76 61 6c 75 65 3e 5d 29 [<init-value>])
99b0: 7d 0a 0a 44 65 63 6c 61 72 65 73 20 61 20 4a 61 }..Declares a Ja
99c0: 76 61 53 63 72 69 70 74 20 76 61 72 69 61 62 6c vaScript variabl
99d0: 65 2c 20 6f 70 74 69 6f 6e 61 6c 6c 79 20 77 69 e, optionally wi
99e0: 74 68 20 61 6e 20 69 6e 69 74 69 61 6c 20 76 61 th an initial va
99f0: 6c 75 65 2e 0a 0a 5c 73 75 62 73 75 62 73 65 63 lue...\subsubsec
9a00: 74 69 6f 6e 2a 7b 28 6a 73 2d 63 6f 6d 6d 65 6e tion*{(js-commen
9a10: 74 20 3c 66 6f 72 6d 61 74 74 65 72 3e 20 2e 2e t <formatter> ..
9a20: 2e 29 7d 0a 0a 46 6f 72 6d 61 74 73 20 61 20 63 .)}..Formats a c
9a30: 6f 6d 6d 65 6e 74 20 70 72 65 66 69 78 69 6e 67 omment prefixing
9a40: 20 6c 69 6e 65 73 20 77 69 74 68 20 5c 71 7b 22 lines with \q{"
9a50: 2f 2f 20 22 7d 2e 0a 0a 5c 73 65 63 74 69 6f 6e // "}...\section
9a60: 7b 46 6f 72 6d 61 74 74 69 6e 67 20 77 69 74 68 {Formatting with
9a70: 20 43 6f 6c 6f 72 7d 0a 0a 54 68 65 20 66 6d 74 Color}..The fmt
9a80: 2d 63 6f 6c 6f 72 20 6c 69 62 72 61 72 79 20 70 -color library p
9a90: 72 6f 76 69 64 65 73 20 74 68 65 20 66 6f 6c 6c rovides the foll
9aa0: 6f 77 69 6e 67 20 75 74 69 6c 69 74 69 65 73 3a owing utilities:
9ab0: 0a 0a 5c 71 7b 0a 20 20 28 66 6d 74 2d 72 65 64 ..\q{. (fmt-red
9ac0: 20 3c 66 6f 72 6d 61 74 74 65 72 3e 20 2e 2e 2e <formatter> ...
9ad0: 29 0a 20 20 28 66 6d 74 2d 62 6c 75 65 20 3c 66 ). (fmt-blue <f
9ae0: 6f 72 6d 61 74 74 65 72 3e 20 2e 2e 2e 29 0a 20 ormatter> ...).
9af0: 20 28 66 6d 74 2d 67 72 65 65 6e 20 3c 66 6f 72 (fmt-green <for
9b00: 6d 61 74 74 65 72 3e 20 2e 2e 2e 29 0a 20 20 28 matter> ...). (
9b10: 66 6d 74 2d 63 79 61 6e 20 3c 66 6f 72 6d 61 74 fmt-cyan <format
9b20: 74 65 72 3e 20 2e 2e 2e 29 0a 20 20 28 66 6d 74 ter> ...). (fmt
9b30: 2d 79 65 6c 6c 6f 77 20 3c 66 6f 72 6d 61 74 74 -yellow <formatt
9b40: 65 72 3e 20 2e 2e 2e 29 0a 20 20 28 66 6d 74 2d er> ...). (fmt-
9b50: 6d 61 67 65 6e 74 61 20 3c 66 6f 72 6d 61 74 74 magenta <formatt
9b60: 65 72 3e 20 2e 2e 2e 29 0a 20 20 28 66 6d 74 2d er> ...). (fmt-
9b70: 77 68 69 74 65 20 3c 66 6f 72 6d 61 74 74 65 72 white <formatter
9b80: 3e 20 2e 2e 2e 29 0a 20 20 28 66 6d 74 2d 62 6c > ...). (fmt-bl
9b90: 61 63 6b 20 3c 66 6f 72 6d 61 74 74 65 72 3e 20 ack <formatter>
9ba0: 2e 2e 2e 29 0a 20 20 28 66 6d 74 2d 62 6f 6c 64 ...). (fmt-bold
9bb0: 20 3c 66 6f 72 6d 61 74 74 65 72 3e 20 2e 2e 2e <formatter> ...
9bc0: 29 0a 20 20 28 66 6d 74 2d 75 6e 64 65 72 6c 69 ). (fmt-underli
9bd0: 6e 65 20 3c 66 6f 72 6d 61 74 74 65 72 3e 20 2e ne <formatter> .
9be0: 2e 2e 29 0a 7d 0a 0a 61 6e 64 20 6d 6f 72 65 20 ..).}..and more
9bf0: 67 65 6e 65 72 61 6c 6c 79 0a 0a 20 20 5c 71 7b generally.. \q{
9c00: 28 66 6d 74 2d 63 6f 6c 6f 72 20 3c 63 6f 6c 6f (fmt-color <colo
9c10: 72 3e 20 3c 66 6f 72 6d 61 74 74 65 72 3e 20 2e r> <formatter> .
9c20: 2e 2e 29 7d 0a 0a 77 68 65 72 65 20 63 6f 6c 6f ..)}..where colo
9c30: 72 20 63 61 6e 20 62 65 20 61 20 73 79 6d 62 6f r can be a symbo
9c40: 6c 20 6e 61 6d 65 20 6f 72 20 5c 71 7b 23 78 52 l name or \q{#xR
9c50: 52 47 47 42 42 7d 20 6e 75 6d 65 72 69 63 20 76 RGGBB} numeric v
9c60: 61 6c 75 65 2e 0a 4f 75 74 70 75 74 73 20 74 68 alue..Outputs th
9c70: 65 20 66 6f 72 6d 61 74 74 65 72 73 20 63 6f 6c e formatters col
9c80: 6f 72 65 64 20 77 69 74 68 20 41 4e 53 49 20 65 ored with ANSI e
9c90: 73 63 61 70 65 73 2e 20 20 49 6e 20 61 64 64 69 scapes. In addi
9ca0: 74 69 6f 6e 0a 0a 20 20 5c 71 7b 28 66 6d 74 2d tion.. \q{(fmt-
9cb0: 69 6e 2d 68 74 6d 6c 20 3c 66 6f 72 6d 61 74 74 in-html <formatt
9cc0: 65 72 3e 20 2e 2e 2e 29 7d 0a 0a 63 61 6e 20 62 er> ...)}..can b
9cd0: 65 20 75 73 65 64 20 74 6f 20 6d 61 72 6b 20 74 e used to mark t
9ce0: 68 65 20 66 6f 72 6d 61 74 20 73 74 61 74 65 20 he format state
9cf0: 61 73 20 62 65 69 6e 67 20 69 6e 73 69 64 65 20 as being inside
9d00: 48 54 4d 4c 2c 20 77 68 69 63 68 20 74 68 65 0a HTML, which the.
9d10: 61 62 6f 76 65 20 63 6f 6c 6f 72 20 66 6f 72 6d above color form
9d20: 61 74 73 20 77 69 6c 6c 20 75 6e 64 65 72 73 74 ats will underst
9d30: 61 6e 64 20 61 6e 64 20 6f 75 74 70 75 74 20 48 and and output H
9d40: 54 4d 4c 20 5c 71 7b 3c 73 70 61 6e 3e 7d 20 74 TML \q{<span>} t
9d50: 61 67 73 20 77 69 74 68 0a 74 68 65 20 61 70 70 ags with.the app
9d60: 72 6f 70 72 69 61 74 65 20 73 74 79 6c 65 20 63 ropriate style c
9d70: 6f 6c 6f 72 73 2c 20 69 6e 73 74 65 61 64 20 6f olors, instead o
9d80: 66 20 41 4e 53 49 20 65 73 63 61 70 65 73 2e 0a f ANSI escapes..
9d90: 0a 0a 5c 73 65 63 74 69 6f 6e 7b 55 6e 69 63 6f ..\section{Unico
9da0: 64 65 7d 0a 0a 54 68 65 20 66 6d 74 2d 75 6e 69 de}..The fmt-uni
9db0: 63 6f 64 65 20 6c 69 62 72 61 72 79 20 70 72 6f code library pro
9dc0: 76 69 64 65 73 20 74 68 65 20 5c 71 7b 66 6d 74 vides the \q{fmt
9dd0: 2d 75 6e 69 63 6f 64 65 7d 20 66 6f 72 6d 61 74 -unicode} format
9de0: 74 65 72 2c 20 77 68 69 63 68 0a 6a 75 73 74 20 ter, which.just
9df0: 74 61 6b 65 73 20 61 20 6c 69 73 74 20 6f 66 20 takes a list of
9e00: 66 6f 72 6d 61 74 74 65 72 73 20 61 6e 64 20 6f formatters and o
9e10: 76 65 72 72 69 64 65 73 20 74 68 65 20 73 74 72 verrides the str
9e20: 69 6e 67 2d 6c 65 6e 67 74 68 20 66 6f 72 0a 70 ing-length for.p
9e30: 61 64 64 69 6e 67 20 61 6e 64 20 74 72 69 6d 6d adding and trimm
9e40: 69 6e 67 2c 20 73 75 63 68 20 74 68 61 74 20 55 ing, such that U
9e50: 6e 69 63 6f 64 65 20 64 6f 75 62 6c 65 20 6f 72 nicode double or
9e60: 20 66 75 6c 6c 20 77 69 64 74 68 0a 63 68 61 72 full width.char
9e70: 61 63 74 65 72 73 20 61 72 65 20 63 6f 6e 73 69 acters are consi
9e80: 64 65 72 65 64 20 32 20 63 68 61 72 61 63 74 65 dered 2 characte
9e90: 72 73 20 77 69 64 65 20 28 61 73 20 74 68 65 79 rs wide (as they
9ea0: 20 74 79 70 69 63 61 6c 6c 79 20 61 72 65 20 69 typically are i
9eb0: 6e 0a 66 69 78 65 64 2d 77 69 64 74 68 20 74 65 n.fixed-width te
9ec0: 72 6d 69 6e 61 6c 73 29 2c 20 77 68 69 6c 65 20 rminals), while
9ed0: 74 72 65 61 74 69 6e 67 20 63 6f 6d 62 69 6e 69 treating combini
9ee0: 6e 67 20 61 6e 64 20 6e 6f 6e 2d 73 70 61 63 69 ng and non-spaci
9ef0: 6e 67 0a 63 68 61 72 61 63 74 65 72 73 20 61 73 ng.characters as
9f00: 20 30 20 63 68 61 72 61 63 74 65 72 73 20 77 69 0 characters wi
9f10: 64 65 2e 0a 0a 49 74 20 61 6c 73 6f 20 72 65 63 de...It also rec
9f20: 6f 67 6e 69 7a 65 73 20 61 6e 64 20 69 67 6e 6f ognizes and igno
9f30: 72 65 73 20 41 4e 53 49 20 65 73 63 61 70 65 73 res ANSI escapes
9f40: 2c 20 69 6e 20 70 61 72 74 69 63 75 6c 61 72 20 , in particular
9f50: 75 73 65 66 75 6c 20 69 66 0a 79 6f 75 20 77 61 useful if.you wa
9f60: 6e 74 20 74 6f 20 63 6f 6d 62 69 6e 65 20 74 68 nt to combine th
9f70: 69 73 20 77 69 74 68 20 74 68 65 20 66 6d 74 2d is with the fmt-
9f80: 63 6f 6c 6f 72 20 75 74 69 6c 69 74 69 65 73 2e color utilities.
9f90: 0a 0a 0a 5c 73 65 63 74 69 6f 6e 7b 4f 70 74 69 ...\section{Opti
9fa0: 6d 69 7a 69 6e 67 7d 0a 0a 54 68 65 20 6c 69 62 mizing}..The lib
9fb0: 72 61 72 79 20 69 73 20 64 65 73 69 67 6e 65 64 rary is designed
9fc0: 20 66 6f 72 20 73 63 61 6c 61 62 69 6c 69 74 79 for scalability
9fd0: 20 61 6e 64 20 66 6c 65 78 69 62 69 6c 69 74 79 and flexibility
9fe0: 2c 20 6e 6f 74 20 73 70 65 65 64 2c 0a 61 6e 64 , not speed,.and
9ff0: 20 49 27 6d 20 6e 6f 74 20 67 6f 69 6e 67 20 74 I'm not going t
a000: 6f 20 74 68 69 6e 6b 20 61 62 6f 75 74 20 61 6e o think about an
a010: 79 20 66 69 6e 65 20 74 75 6e 69 6e 67 20 75 6e y fine tuning un
a020: 74 69 6c 20 69 74 27 73 20 6d 6f 72 65 0a 73 74 til it's more.st
a030: 61 62 69 6c 69 73 65 64 2e 20 20 4f 6e 65 20 61 abilised. One a
a040: 73 70 65 63 74 20 6f 66 20 74 68 65 20 64 65 73 spect of the des
a050: 69 67 6e 2c 20 68 6f 77 65 76 65 72 2c 20 77 61 ign, however, wa
a060: 73 20 69 6e 66 6c 75 65 6e 63 65 64 20 66 6f 72 s influenced for
a070: 20 74 68 65 0a 73 61 6b 65 20 6f 66 20 66 75 74 the.sake of fut
a080: 75 72 65 20 6f 70 74 69 6d 69 7a 61 74 69 6f 6e ure optimization
a090: 73 2c 20 77 68 69 63 68 20 69 73 20 74 68 61 74 s, which is that
a0a0: 20 6e 6f 6e 65 20 6f 66 20 74 68 65 20 64 65 66 none of the def
a0b0: 61 75 6c 74 20 66 6f 72 6d 61 74 0a 76 61 72 69 ault format.vari
a0c0: 61 62 6c 65 73 20 61 72 65 20 69 6e 69 74 69 61 ables are initia
a0d0: 6c 69 7a 65 64 20 62 79 20 67 6c 6f 62 61 6c 20 lized by global
a0e0: 70 61 72 61 6d 65 74 65 72 73 2c 20 77 68 69 63 parameters, whic
a0f0: 68 20 6c 65 61 76 65 73 20 72 6f 6f 6d 20 66 6f h leaves room fo
a100: 72 0a 69 6e 6c 69 6e 69 6e 67 20 61 6e 64 20 73 r.inlining and s
a110: 75 62 73 65 71 75 65 6e 74 20 73 69 6d 70 6c 69 ubsequent simpli
a120: 66 69 63 61 74 69 6f 6e 20 6f 66 20 66 6f 72 6d fication of form
a130: 61 74 20 63 61 6c 6c 73 2e 0a 0a 49 66 20 79 6f at calls...If yo
a140: 75 20 64 6f 6e 27 74 20 68 61 76 65 20 61 6e 20 u don't have an
a150: 61 67 67 72 65 73 73 69 76 65 6c 79 20 6f 70 74 aggressively opt
a160: 69 6d 69 7a 69 6e 67 20 63 6f 6d 70 69 6c 65 72 imizing compiler
a170: 2c 20 79 6f 75 20 63 61 6e 20 65 61 73 69 6c 79 , you can easily
a180: 0a 61 63 68 69 65 76 65 20 6c 61 72 67 65 20 73 .achieve large s
a190: 70 65 65 64 75 70 73 20 6f 6e 20 63 6f 6d 6d 6f peedups on commo
a1a0: 6e 20 63 61 73 65 73 20 77 69 74 68 20 43 4c 2d n cases with CL-
a1b0: 73 74 79 6c 65 20 63 6f 6d 70 69 6c 65 72 20 6d style compiler m
a1c0: 61 63 72 6f 73 2e 0a 0a 5c 73 65 63 74 69 6f 6e acros...\section
a1d0: 7b 43 6f 6d 6d 6f 6e 20 4c 69 73 70 20 46 6f 72 {Common Lisp For
a1e0: 6d 61 74 20 43 68 65 61 74 20 53 68 65 65 74 7d mat Cheat Sheet}
a1f0: 0a 0a 41 20 71 75 69 63 6b 20 72 65 66 65 72 65 ..A quick refere
a200: 6e 63 65 20 66 6f 72 20 74 68 6f 73 65 20 6f 66 nce for those of
a210: 20 79 6f 75 20 73 77 69 74 63 68 69 6e 67 20 6f you switching o
a220: 76 65 72 20 66 72 6f 6d 20 43 6f 6d 6d 6f 6e 20 ver from Common
a230: 4c 69 73 70 27 73 0a 66 6f 72 6d 61 74 2e 0a 0a Lisp's.format...
a240: 5c 74 61 62 6c 65 7b 0a 5c 62 7b 66 6f 72 6d 61 \table{.\b{forma
a250: 74 7d 20 7c 20 5c 62 7b 66 6d 74 7d 0a 7e 61 20 t} | \b{fmt}.~a
a260: 7c 20 5c 71 7b 64 73 70 7d 0a 7e 63 20 7c 20 5c | \q{dsp}.~c | \
a270: 71 7b 64 73 70 7d 0a 7e 73 20 7c 20 5c 71 7b 77 q{dsp}.~s | \q{w
a280: 72 74 2f 75 6e 73 68 61 72 65 64 7d 0a 7e 77 20 rt/unshared}.~w
a290: 7c 20 5c 71 7b 77 72 74 7d 0a 7e 79 20 7c 20 5c | \q{wrt}.~y | \
a2a0: 71 7b 70 72 65 74 74 79 7d 0a 7e 78 20 7c 20 5c q{pretty}.~x | \
a2b0: 71 7b 28 72 61 64 69 78 20 31 36 20 2e 2e 2e 29 q{(radix 16 ...)
a2c0: 7d 20 6f 72 20 5c 71 7b 28 6e 75 6d 20 3c 6e 3e } or \q{(num <n>
a2d0: 20 31 36 29 7d 0a 7e 6f 20 7c 20 5c 71 7b 28 72 16)}.~o | \q{(r
a2e0: 61 64 69 78 20 38 20 2e 2e 2e 29 7d 20 6f 72 20 adix 8 ...)} or
a2f0: 5c 71 7b 28 6e 75 6d 20 3c 6e 3e 20 38 29 7d 0a \q{(num <n> 8)}.
a300: 7e 62 20 7c 20 5c 71 7b 28 72 61 64 69 78 20 32 ~b | \q{(radix 2
a310: 20 2e 2e 2e 29 7d 20 6f 72 20 5c 71 7b 28 6e 75 ...)} or \q{(nu
a320: 6d 20 3c 6e 3e 20 32 29 7d 0a 7e 66 20 7c 20 5c m <n> 2)}.~f | \
a330: 71 7b 28 66 69 78 20 3c 64 69 67 69 74 73 3e 20 q{(fix <digits>
a340: 2e 2e 2e 29 7d 20 6f 72 20 5c 71 7b 28 6e 75 6d ...)} or \q{(num
a350: 20 3c 6e 3e 20 3c 72 61 64 69 78 3e 20 3c 64 69 <n> <radix> <di
a360: 67 69 74 73 3e 29 7d 0a 7e 25 20 7c 20 5c 71 7b gits>)}.~% | \q{
a370: 6e 6c 7d 0a 7e 26 20 7c 20 5c 71 7b 66 6c 7d 0a nl}.~& | \q{fl}.
a380: 7e 5b 2e 2e 2e 7e 5d 20 7c 20 6e 6f 72 6d 61 6c ~[...~] | normal
a390: 20 5c 71 7b 69 66 7d 20 6f 72 20 5c 71 7b 66 6d \q{if} or \q{fm
a3a0: 74 2d 69 66 7d 20 28 64 65 6c 61 79 65 64 20 74 t-if} (delayed t
a3b0: 65 73 74 29 0a 7e 7b 2e 2e 2e 7e 7d 20 7c 20 5c est).~{...~} | \
a3c0: 71 7b 28 66 6d 74 2d 6a 6f 69 6e 20 2e 2e 2e 20 q{(fmt-join ...
a3d0: 3c 6c 69 73 74 3e 20 5b 3c 73 65 70 3e 5d 29 7d <list> [<sep>])}
a3e0: 0a 7d 0a 0a 5c 73 65 63 74 69 6f 6e 7b 52 65 66 .}..\section{Ref
a3f0: 65 72 65 6e 63 65 73 7d 0a 0a 5c 62 69 62 69 74 erences}..\bibit
a400: 65 6d 7b 52 35 52 53 7d 20 52 2e 20 4b 65 6c 73 em{R5RS} R. Kels
a410: 65 79 2c 20 57 2e 20 43 6c 69 6e 67 65 72 2c 20 ey, W. Clinger,
a420: 4a 2e 20 52 65 65 73 20 28 65 64 73 2e 29 0a 5c J. Rees (eds.).\
a430: 75 72 6c 68 7b 68 74 74 70 3a 2f 2f 77 77 77 2e urlh{http://www.
a440: 73 63 68 65 6d 65 72 73 2e 6f 72 67 2f 44 6f 63 schemers.org/Doc
a450: 75 6d 65 6e 74 73 2f 53 74 61 6e 64 61 72 64 73 uments/Standards
a460: 2f 52 35 52 53 2f 7d 7b 52 65 76 69 73 65 64 5e /R5RS/}{Revised^
a470: 35 20 52 65 70 6f 72 74 20 6f 6e 20 74 68 65 20 5 Report on the
a480: 41 6c 67 6f 72 69 74 68 6d 69 63 20 4c 61 6e 67 Algorithmic Lang
a490: 75 61 67 65 20 53 63 68 65 6d 65 7d 0a 0a 5c 62 uage Scheme}..\b
a4a0: 69 62 69 74 65 6d 7b 43 6f 6d 6d 6f 6e 4c 69 73 ibitem{CommonLis
a4b0: 70 7d 20 47 75 79 20 4c 2e 20 53 74 65 65 6c 65 p} Guy L. Steele
a4c0: 20 4a 72 2e 20 28 65 64 69 74 6f 72 29 0a 5c 75 Jr. (editor).\u
a4d0: 72 6c 68 7b 68 74 74 70 3a 2f 2f 77 77 77 2e 68 rlh{http://www.h
a4e0: 61 72 6c 65 71 75 69 6e 2e 63 6f 6d 2f 65 64 75 arlequin.com/edu
a4f0: 63 61 74 69 6f 6e 2f 62 6f 6f 6b 73 2f 48 79 70 cation/books/Hyp
a500: 65 72 53 70 65 63 2f 7d 7b 43 6f 6d 6d 6f 6e 20 erSpec/}{Common
a510: 4c 69 73 70 20 48 79 70 65 72 73 70 65 63 7d 0a Lisp Hyperspec}.
a520: 0a 5c 62 69 62 69 74 65 6d 7b 53 52 46 49 2d 32 .\bibitem{SRFI-2
a530: 38 7d 20 53 63 6f 74 74 20 47 2e 20 4d 69 6c 6c 8} Scott G. Mill
a540: 65 72 0a 5c 75 72 6c 68 7b 68 74 74 70 3a 2f 2f er.\urlh{http://
a550: 73 72 66 69 2e 73 63 68 65 6d 65 72 73 2e 6f 72 srfi.schemers.or
a560: 67 2f 73 72 66 69 2d 32 38 2f 7d 7b 53 52 46 49 g/srfi-28/}{SRFI
a570: 2d 32 38 20 42 61 73 69 63 20 46 6f 72 6d 61 74 -28 Basic Format
a580: 20 53 74 72 69 6e 67 73 7d 0a 0a 5c 62 69 62 69 Strings}..\bibi
a590: 74 65 6d 7b 53 52 46 49 2d 34 38 7d 20 4b 65 6e tem{SRFI-48} Ken
a5a0: 20 44 69 63 6b 65 79 0a 5c 75 72 6c 68 7b 68 74 Dickey.\urlh{ht
a5b0: 74 70 3a 2f 2f 73 72 66 69 2e 73 63 68 65 6d 65 tp://srfi.scheme
a5c0: 72 73 2e 6f 72 67 2f 73 72 66 69 2d 34 38 2f 7d rs.org/srfi-48/}
a5d0: 7b 53 52 46 49 2d 34 38 20 49 6e 74 65 72 6d 65 {SRFI-48 Interme
a5e0: 64 69 61 74 65 20 46 6f 72 6d 61 74 20 53 74 72 diate Format Str
a5f0: 69 6e 67 73 7d 0a 0a 5c 62 69 62 69 74 65 6d 7b ings}..\bibitem{
a600: 53 52 46 49 2d 33 38 7d 20 52 61 79 20 44 69 6c SRFI-38} Ray Dil
a610: 6c 69 6e 67 65 72 0a 5c 75 72 6c 68 7b 68 74 74 linger.\urlh{htt
a620: 70 3a 2f 2f 73 72 66 69 2e 73 63 68 65 6d 65 72 p://srfi.schemer
a630: 73 2e 6f 72 67 2f 73 72 66 69 2d 33 38 2f 7d 7b s.org/srfi-38/}{
a640: 53 52 46 49 2d 33 38 20 45 78 74 65 72 6e 61 6c SRFI-38 External
a650: 20 52 65 70 72 65 73 65 6e 74 61 74 69 6f 6e 20 Representation
a660: 66 6f 72 20 44 61 74 61 20 57 69 74 68 20 53 68 for Data With Sh
a670: 61 72 65 64 20 53 74 72 75 63 74 75 72 65 7d 0a ared Structure}.
a680: 0a 5c 62 69 62 69 74 65 6d 7b 50 65 72 6c 36 7d .\bibitem{Perl6}
a690: 20 44 61 6d 69 61 6e 20 43 6f 6e 77 61 79 0a 5c Damian Conway.\
a6a0: 75 72 6c 68 7b 68 74 74 70 3a 2f 2f 77 77 77 2e urlh{http://www.
a6b0: 70 65 72 6c 2e 63 6f 6d 2f 6c 70 74 2f 61 2f 38 perl.com/lpt/a/8
a6c0: 31 39 7d 7b 50 65 72 6c 36 20 45 78 65 67 65 73 19}{Perl6 Exeges
a6d0: 69 73 20 37 20 2d 20 66 6f 72 6d 61 74 74 69 6e is 7 - formattin
a6e0: 67 7d 0a 0a 5c 65 76 61 6c 28 64 69 73 70 6c 61 g}..\eval(displa
a6f0: 79 20 22 3c 62 72 20 2f 3e 3c 62 72 20 2f 3e 3c y "<br /><br /><
a700: 62 72 20 2f 3e 3c 62 72 20 2f 3e 5c 6e 22 29 0a br /><br />\n").
a710: 0a .