io-ext.texi 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. @node I/O extensions
  2. @section I/O extensions
  3. @stindex extended-ports
  4. These facilities are all exported from the @code{extended-ports}
  5. structure.
  6. @cindex ports with line & column numbers
  7. @cindex line- & column-tracking ports
  8. @cindex ports that track line & column numbers
  9. Tracking ports track the line & column number that they are on.
  10. @deffn procedure make-tracking-input-port sub-port @returns{} input-port
  11. @deffnx procedure make-tracking-output-port sub-port @returns{} output-port
  12. Tracking port constructors. These simply create wrapper ports around
  13. @var{sub-port} that track the line & column numbers.
  14. @end deffn
  15. @deffn procedure current-row port @returns{} integer or @code{#f}
  16. @deffnx procedure current-column port @returns{} integer or @code{#f}
  17. Accessors for line (row) & column number information. If @var{port} is
  18. a not a tracking port, these simply return @code{#f}.
  19. @end deffn
  20. @deffn procedure fresh-line port @returns{} unspecified
  21. This writes a newline to port with @code{newline}, unless it can be
  22. determined that the previous character was a newline --- that is, if
  23. @code{(current-column @var{port})} does not evaluate to zero.
  24. @end deffn
  25. @cindex character source input ports
  26. @cindex character sink output ports
  27. @cindex simple character source input ports
  28. @cindex simple character sink output ports
  29. These are ports based on procedures that produce and consume single
  30. characters at a time.
  31. @deffn procedure char-source->input-port char-producer [readiness-tester closer] @returns{} input-port
  32. @deffnx procedure char-sink->output-port char-consumer @returns{} output-port
  33. @code{Char-source->input-port} creates an input port that calls
  34. @var{char-producer} with zero arguments when a character is read from
  35. it. If @var{readiness-tester} is present, it is used for the
  36. @code{char-ready?} operation on the resulting port; likewise with
  37. @var{closer} and @code{close-input-port}.
  38. @code{Char-sink->output-port} creates an output port that calls
  39. @var{char-consumer} for every character written to it.
  40. @end deffn
  41. @cindex string ports
  42. @cindex string input ports
  43. @cindex string output ports
  44. @cindex input ports from strings
  45. @cindex output ports to strings
  46. Scheme48 also provides ports that collect and produce output to and
  47. from strings.
  48. @deffn procedure make-string-input-port string @returns{} input-port
  49. Constructs an input port whose contents are read from @var{string}.
  50. @end deffn
  51. @deffn procedure make-string-output-port @returns{} output-port
  52. @deffnx procedure string-output-port-output string-port @returns{} string
  53. @deffnx procedure call-with-string-output-port receiver @returns{} string
  54. @code{Make-string-output-port} makes an output port that collects its
  55. output in a string. @code{String-output-port-output} returns the
  56. string that @var{string-port} collected.
  57. @code{Call-with-string-output-port} creates a string output port,
  58. applies @var{receiver} to it, and returns the string that the string
  59. output port collected.
  60. @end deffn
  61. @cindex limiting output
  62. Finally, there is a facility for writing only a limited quantity of
  63. output to a given port.
  64. @deffn procedure limit-output port count receiver @returns{} unspecified
  65. @code{Limit-output} applies @var{receiver} to a port that will write at
  66. most @var{count} characters to @var{port}.
  67. @end deffn