/racket-5-0-2-bin-i386-osx-mac-dmg/collects/scribblings/drracket/printing.scrbl

http://github.com/smorin/f4f.arc · Racket · 89 lines · 76 code · 13 blank · 0 comment · 0 complexity · 16f2029f30997c47a205aedf57c2f27e MD5 · raw file

  1. #lang scribble/doc
  2. @(require "common.ss"
  3. scribble/struct)
  4. @(define spacer (hspace 1))
  5. @(define-syntax-rule (print-table [expr cons qq wr] ...)
  6. (*print-table (list (list spacer (racket expr) spacer (racketresult cons) spacer (racketresult qq) spacer (racketresult wr)) ...)))
  7. @(define (*print-table rows)
  8. (make-table
  9. #f
  10. (cons
  11. (list (make-flow (list (make-paragraph (list spacer))))
  12. (make-flow (list @t{Input expression}))
  13. (make-flow (list (make-paragraph (list spacer))))
  14. (make-flow (list @t{@onscreen{Constructor}}))
  15. (make-flow (list (make-paragraph (list spacer))))
  16. (make-flow (list @t{@onscreen{Quasiquote}}))
  17. (make-flow (list (make-paragraph (list spacer))))
  18. (make-flow (list @t{@onscreen{write}})))
  19. (map (lambda (row)
  20. (map (lambda (e)
  21. (make-flow (list (make-paragraph (list e)))))
  22. row))
  23. rows))))
  24. @title[#:tag "output-syntax"]{Output Printing Styles}
  25. @section-index["printing format"]
  26. Many Racket languages support a @onscreen{Output Syntax} choice that
  27. determines how evaluation results are printed in the
  28. @tech{interactions window}. This setting also applies to output
  29. generated by calling @racket[print] explicitly.
  30. The @onscreen{print} style is the normal Racket output style. The
  31. following table illustrates the other output styles:
  32. @print-table[
  33. [(cons 1 2) (cons 1 2) `(1 . 2) (1 . 2)]
  34. [(list 1 2) (list 1 2) `(1 2) (1 2)]
  35. ['(1 2) (list 1 2) `(1 2) (1 2)]
  36. [(list (void)) (list (void)) `(,(void)) (#,(@racketresultfont "#<void>"))]
  37. [`(,(void)) (list (void)) `(,(void)) (#,(racketresultfont "#<void>"))]
  38. [(vector 1 2 3) (vector 1 2 3) (vector 1 2 3) #(1 2 3)]
  39. [(box 1) (box 1) (box 1) #&1]
  40. [(lambda (x) x) (lambda (a1) ...) (lambda (a1) ...) #,(racketresultfont "#<procedure>")]
  41. ['sym 'sym 'sym sym]
  42. [(make-s 1 2) (make-s 1 2) (make-s 1 2) #(struct:s 1 2)]
  43. ['() empty `() ()]
  44. [add1 add1 add1 #,(racketresultfont "#<procedure:add1>")]
  45. [(delay 1) (delay ...) (delay ...) #,(racketresultfont "#<promise>")]
  46. [(regexp "a") (regexp "a") (regexp "a") #rx"a"]
  47. ]
  48. The @as-index{@onscreen{Constructor} output} mode is similar to
  49. Rackets normal print mode, except that even quotable are still printed
  50. with constructors, constructor functions and forms are used to
  51. approximate some otherwise unprintable values. For example,
  52. @onscreen{Constructor} output prints a procedure in a
  53. @racketresult[lambda] form. For output to a graphical context,
  54. rational numbers are printed using a special @racket[snip%] object
  55. that lets the user choose between improper fractions, mixed fractions,
  56. and repeating decimals.
  57. The @as-index{@onscreen{Quasiquote} output} mode is like
  58. @onscreen{Constructor} output, but it uses @racket[quasiquote]
  59. (abbreviated with @litchar{`}) to print lists, and it uses
  60. @racket[unquote] (abbreviated with @litchar{,}) to escape back to
  61. @onscreen{Constructor} printing as needed.
  62. The @as-index{@onscreen{write} output} mode corresponds to traditional
  63. Scheme printing via the @racket[write] procedure. For example, lists
  64. print by parenthesizing the printed form of the list elements, without
  65. a leading quote mark or a constructor name.
  66. Finally, the @as-index{@onscreen{print} output} mode corresponds to
  67. Racket's default printing via the @racket[print] procedure. Output via
  68. @racket[print] is further configurable through run-time settings, such
  69. as the @racket[print-as-expression] parameter, and it may be adjusted
  70. by a @hash-lang[]-specified language. For example, the
  71. @racketmodname[scheme] language sets the @racket[print-as-expression]
  72. parameter to @racket[#f], which essentially makes @onscreen{print}
  73. mode act like @onscreen{write} mode.
  74. For any of the output styles, DrRacket sets the
  75. @racket[global-port-print-handler] so that the @racket[print]
  76. procedure produces output as selected.