Changeset 39472 in project
- Timestamp:
- 12/30/20 17:25:16 (3 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
wiki/eggref/5/format
r37635 r39472 1 [ [tags:egg]]1 [tags:egg]] 2 2 == format 3 3 … … 39 39 Format Specification (Format version 3.1) 40 40 ----------------------------------------- 41 41 42 42 Please consult a Common LISP format reference manual for a detailed 43 43 description of the format string syntax. 44 44 45 45 This implementation supports directive parameters and modifiers (`:' and `@' 46 46 characters). Multiple parameters must be separated by a comma (`,'). … … 49 49 number of rest arguments parameter (`#'), empty and default parameters. 50 50 Directive characters are case independent. 51 51 52 52 The general form of a directive is: 53 53 54 54 DIRECTIVE ::= ~{DIRECTIVE-PARAMETER,}[:][@]DIRECTIVE-CHARACTER 55 55 56 56 DIRECTIVE-PARAMETER ::= [ [-|+]{0-9}+ | 'CHARACTER | v | # ] 57 57 58 58 Implemented CL Format Control Directives 59 59 ........................................ 60 60 61 61 Documentation syntax: Uppercase characters represent the corresponding control 62 62 directive characters. Lowercase characters represent control directive 63 63 parameter descriptions. 64 64 65 65 `~A' 66 66 67 67 Any (print as `display' does). 68 68 69 69 `~@A' 70 70 71 71 left pad. 72 72 73 73 `~MINCOL,COLINC,MINPAD,PADCHARA' 74 74 75 75 full padding. 76 76 77 77 `~S' 78 78 79 79 S-expression (print as `write' does). 80 80 81 81 `~@S' 82 82 83 83 left pad. 84 84 85 85 `~MINCOL,COLINC,MINPAD,PADCHARS' 86 86 87 87 full padding. 88 88 89 89 `~D' 90 90 91 91 Decimal. 92 92 93 93 `~@D' 94 94 95 95 print number sign always. 96 96 97 97 `~:D' 98 98 99 99 print comma separated. 100 100 101 101 `~MINCOL,PADCHAR,COMMACHARD' 102 102 103 103 padding. 104 104 105 105 `~X' 106 106 107 107 Hexadecimal. 108 108 109 109 `~@X' 110 110 111 111 print number sign always. 112 112 113 113 `~:X' 114 114 115 115 print comma separated. 116 116 117 117 `~MINCOL,PADCHAR,COMMACHARX' 118 118 119 119 padding. 120 120 121 121 `~O' 122 122 123 123 Octal. 124 124 125 125 `~@O' 126 126 127 127 print number sign always. 128 128 129 129 `~:O' 130 130 131 131 print comma separated. 132 132 133 133 `~MINCOL,PADCHAR,COMMACHARO' 134 134 135 135 padding. 136 136 137 137 `~B' 138 138 139 139 Binary. 140 140 141 141 `~@B' 142 142 143 143 print number sign always. 144 144 145 145 `~:B' 146 146 147 147 print comma separated. 148 148 149 149 `~MINCOL,PADCHAR,COMMACHARB' 150 150 151 151 padding. 152 152 153 153 `~NR' 154 154 155 155 Radix N. 156 156 157 157 `~N,MINCOL,PADCHAR,COMMACHARR' 158 158 159 159 padding. 160 160 161 161 `~@R' 162 162 163 163 print a number as a Roman numeral. 164 164 165 165 `~:@R' 166 166 167 167 print a number as an "old fashioned" Roman numeral. 168 168 169 169 `~:R' 170 170 171 171 print a number as an ordinal English number. 172 172 173 173 `~R' 174 174 175 175 print a number as a cardinal English number. 176 176 177 177 `~P' 178 178 179 179 Plural. 180 180 181 181 `~@P' 182 182 183 183 prints `y' and `ies'. 184 184 185 185 `~:P' 186 186 187 187 as `~P but jumps 1 argument backward.' 188 188 189 189 `~:@P' 190 190 191 191 as `~@P but jumps 1 argument backward.' 192 192 193 193 `~C' 194 194 195 195 Character. 196 196 197 197 `~@C' 198 198 199 199 prints a character as the reader can understand it (i.e. `#\' prefixing). 200 200 201 201 `~:C' 202 202 203 203 prints a character as emacs does (eg. `^C' for ASCII 03). 204 204 205 205 `~F' 206 206 207 207 Fixed-format floating-point (prints a flonum like MMM.NNN). 208 208 209 209 `~WIDTH,DIGITS,SCALE,OVERFLOWCHAR,PADCHARF' 210 210 211 211 `~@F' 212 212 If the number is positive a plus sign is printed. 213 213 214 214 `~E' 215 215 216 216 Exponential floating-point (prints a flonum like MMM.NNN`E'EE). 217 217 218 218 `~WIDTH,DIGITS,EXPONENTDIGITS,SCALE,OVERFLOWCHAR,PADCHAR,EXPONENTCHARE' 219 219 220 220 `~@E' 221 221 222 222 If the number is positive a plus sign is printed. 223 223 224 224 `~G' 225 225 226 226 General floating-point (prints a flonum either fixed or exponential). 227 227 228 228 `~WIDTH,DIGITS,EXPONENTDIGITS,SCALE,OVERFLOWCHAR,PADCHAR,EXPONENTCHARG' 229 229 230 230 `~@G' 231 231 232 232 If the number is positive a plus sign is printed. 233 233 234 234 `~$' 235 235 236 236 Dollars floating-point (prints a flonum in fixed with signs separated). 237 237 238 238 `~DIGITS,SCALE,WIDTH,PADCHAR$' 239 239 240 240 `~@$' 241 241 242 242 If the number is positive a plus sign is printed. 243 243 244 244 `~:@$' 245 245 246 246 A sign is always printed and appears before the padding. 247 247 248 248 `~:$' 249 249 250 250 The sign appears before the padding. 251 251 252 252 `~%' 253 253 254 254 Newline. 255 255 256 256 `~N%' 257 257 258 258 print N newlines. 259 259 260 260 `~&' 261 261 262 262 print newline if not at the beginning of the output line. 263 263 264 264 `~N&' 265 265 266 266 prints `~&' and then N-1 newlines. 267 267 268 268 `~|' 269 269 270 270 Page Separator. 271 271 272 272 `~N|' 273 273 274 274 print N page separators. 275 275 276 276 `~~' 277 277 278 278 Tilde. 279 279 280 280 `~N~' 281 281 282 282 print N tildes. 283 283 284 284 `~'<newline> 285 285 286 286 Continuation Line. 287 287 288 288 `~:'<newline> 289 289 290 290 newline is ignored, white space left. 291 291 292 292 `~@'<newline> 293 293 294 294 newline is left, white space ignored. 295 295 296 296 `~T' 297 297 298 298 Tabulation. 299 299 300 300 `~@T' 301 301 302 302 relative tabulation. 303 303 304 304 `~COLNUM,COLINCT' 305 305 306 306 full tabulation. 307 307 308 308 `~?' 309 309 310 310 Indirection (expects indirect arguments as a list). 311 311 312 312 `~@?' 313 313 314 314 extracts indirect arguments from format arguments. 315 315 316 316 `~(STR~)' 317 317 318 318 Case conversion (converts by `string-downcase'). 319 319 320 320 `~:(STR~)' 321 321 322 322 converts by `string-capitalize'. 323 323 324 324 `~@(STR~)' 325 325 326 326 converts by `string-capitalize-first'. 327 327 328 328 `~:@(STR~)' 329 329 330 330 converts by `string-upcase'. 331 331 332 332 `~*' 333 333 334 334 Argument Jumping (jumps 1 argument forward). 335 335 336 336 `~N*' 337 337 338 338 jumps N arguments forward. 339 339 340 340 `~:*' 341 341 342 342 jumps 1 argument backward. 343 343 344 344 `~N:*' 345 345 346 346 jumps N arguments backward. 347 347 348 348 `~@*' 349 349 350 350 jumps to the 0th argument. 351 351 352 352 `~N@*' 353 353 354 354 jumps to the Nth argument (beginning from 0) 355 355 356 356 `~[STR0~;STR1~;...~;STRN~]' 357 357 358 358 Conditional Expression (numerical clause conditional). 359 359 360 360 `~N[' 361 361 362 362 take argument from N. 363 363 364 364 `~@[' 365 365 366 366 true test conditional. 367 367 368 368 `~:[' 369 369 370 370 if-else-then conditional. 371 371 372 372 `~;' 373 373 374 374 clause separator. 375 375 376 376 `~:;' 377 377 378 378 default clause follows. 379 379 380 380 `~{STR~}' 381 381 382 382 Iteration (args come from the next argument (a list)). Iteration 383 383 bounding is controlled by configuration variables 384 384 format:iteration-bounded and format:max-iterations. With both variables 385 385 default, a maximum of 100 iterations will be performed. 386 386 387 387 `~N{' 388 388 389 389 at most N iterations. 390 390 391 391 `~:{' 392 392 393 393 args from next arg (a list of lists). 394 394 395 395 `~@{' 396 396 397 397 args from the rest of arguments. 398 398 399 399 `~:@{' 400 400 401 401 args from the rest args (lists). 402 402 403 403 `~^' 404 404 Up and out. 405 405 406 406 `~N^' 407 407 408 408 aborts if N = 0 409 409 410 410 `~N,M^' 411 411 412 412 aborts if N = M 413 413 414 414 `~N,M,K^' 415 415 416 416 aborts if N <= M <= K 417 417 418 418 Not Implemented CL Format Control Directives 419 419 ............................................ 420 420 421 421 `~:A' 422 422 423 423 print `#f' as an empty list (see below). 424 424 425 425 `~:S' 426 426 427 427 print `#f' as an empty list (see below). 428 428 429 429 `~<~>' 430 430 431 431 Justification. 432 432 433 433 `~:^' 434 434 435 435 (sorry I don't understand its semantics completely) 436 436 437 437 Extended, Replaced and Additional Control Directives 438 438 .................................................... 439 439 440 440 `~MINCOL,PADCHAR,COMMACHAR,COMMAWIDTHD' 441 441 442 442 `~MINCOL,PADCHAR,COMMACHAR,COMMAWIDTHX' 443 443 444 444 `~MINCOL,PADCHAR,COMMACHAR,COMMAWIDTHO' 445 445 446 446 `~MINCOL,PADCHAR,COMMACHAR,COMMAWIDTHB' 447 447 448 448 `~N,MINCOL,PADCHAR,COMMACHAR,COMMAWIDTHR' 449 449 450 450 COMMAWIDTH is the number of characters between two comma 451 451 characters. 452 452 453 453 `~I' 454 454 print a R4RS complex number as `~F~@Fi' with passed parameters for 455 455 `~F'. 456 456 457 457 `~Y' 458 458 459 459 Pretty print formatting of an argument for scheme code lists. 460 460 461 461 `~K' 462 462 463 463 Same as `~?.' 464 464 465 465 `~!' 466 466 467 467 Flushes the output if format DESTINATION is a port. 468 468 469 469 `~_' 470 470 471 471 Print a `#\space' character 472 472 473 473 `~N_' 474 474 print N `#\space' characters. 475 475 476 476 `~/' 477 477 478 478 Print a `#\tab' character 479 479 480 480 `~N/' 481 481 print N `#\tab' characters. 482 482 483 483 `~NC' 484 484 485 485 Takes N as an integer representation for a character. No arguments 486 486 are consumed. N is converted to a character by `integer->char'. N 487 487 must be a positive decimal number. 488 488 489 489 `~:S' 490 490 491 491 Print out readproof. Prints out internal objects represented as 492 492 `#<...>' as strings `"#<...>"' so that the format output can always 493 493 be processed by `read'. 494 494 495 495 `~:A' 496 496 497 497 Print out readproof. Prints out internal objects represented as 498 498 `#<...>' as strings `"#<...>"' so that the format output can always 499 499 be processed by `read'. 500 500 501 501 `~Q' 502 502 503 503 Prints information and a copyright notice on the format 504 504 implementation. 505 505 506 506 `~:Q' 507 507 prints format version. 508 508 509 509 `~F, ~E, ~G, ~$' 510 510 511 511 May also print number strings, i.e. passing a number as a string and 512 512 format it accordingly. 513 513 514 514 Configuration Variables 515 515 ----------------------- 516 516 517 517 Format has some configuration variables. There should be no modification 518 518 necessary for the default configuration. If modification is desired the 519 519 variable should be set after the format code is loaded. 520 520 521 521 format:floats 522 522 523 523 System has floating-point numbers. (default #t) 524 524 525 525 format:complex-numbers 526 526 527 527 System has complex numbers. (default #f) 528 528 529 529 format:fn-max 530 530 531 531 Maximum number of number digits. (default 200) 532 532 533 533 format:format:en-max 534 534 535 535 Maximum number of exponent digits. (default 10) 536 536 537 537 format:expch 538 538 539 539 The character prefixing the exponent value in ~E printing. 540 540 (default #\E) 541 541 542 542 format:radix-pref 543 543 544 544 Does number->string add a radix prefix? (default <detects upon load>) 545 545 546 546 format:symbol-case-conv 547 547 548 548 Symbols are converted by symbol->string so the case type of the 549 549 printed symbols is implementation dependent. … … 551 551 conversion), string-upcase, string-downcase or string-capitalize. 552 552 (default #f) 553 553 554 554 format:iobj-case-conv 555 555 556 556 As format:symbol-case-conv but applies for the representation of 557 557 implementation internal objects. (default #f) 558 558 559 559 format:iteration-bounded 560 560 561 561 When #t, a ~{...~} control will iterate no more than the number of 562 562 times specified by format:max-iterations regardless of the number … … 565 565 modifiers and arguments, unless termination is forced by language 566 566 or system limitations. (default #t) 567 567 568 568 format:max-iterations 569 569 570 570 The maximum number of iterations performed by a ~{...~} control. 571 571 Has effect only when format:iteration-bounded is #t. (default 100) 572 572 573 573 format:unprocessed-arguments-error? 574 574 575 575 Are superfluous arguments treated as an error. (default #f) 576 577 578 == Notes579 580 A modular and more robust implementation is available in the [[format-modular.html|format-modular]] extension.581 576 582 577
Note: See TracChangeset
for help on using the changeset viewer.