factor/core/io/stdio.facts

120 lines
5.9 KiB
Plaintext
Raw Normal View History

USING: help io quotations strings ;
2006-01-17 01:02:23 -05:00
2006-08-16 21:55:53 -04:00
HELP: stdio
{ $var-description "Holds a stream, used for various implicit stream operations. Rebound using " { $link with-stream } " and " { $link with-stream* } "." } ;
2006-01-16 02:48:15 -05:00
2006-08-16 21:55:53 -04:00
HELP: close
2006-01-16 02:48:15 -05:00
{ $contract "Closes the " { $link stdio } " stream." }
$io-error ;
2006-08-16 21:55:53 -04:00
HELP: readln
2006-01-16 02:48:15 -05:00
{ $values { "str/f" "a string or " { $link f } } }
{ $contract "Reads a line of input from the " { $link stdio } " stream. Outputs " { $link f } " on stream exhaustion." }
$io-error ;
2006-08-16 21:55:53 -04:00
HELP: read1
2006-01-16 02:48:15 -05:00
{ $values { "ch/f" "a character or " { $link f } } }
{ $contract "Reads a character of input from the " { $link stdio } " stream. Outputs " { $link f } " on stream exhaustion." }
$io-error ;
2006-08-16 21:55:53 -04:00
HELP: read
{ $values { "n" "a non-negative integer" } { "str/f" "a string or " { $link f } } }
2006-01-16 02:48:15 -05:00
{ $contract "Reads " { $snippet "n" } " characters of input from the " { $link stdio } " stream. Outputs a truncated string or " { $link f } " on stream exhaustion." }
$io-error ;
HELP: read-until
{ $values { "seps" "a string" } { "str/f" "a string or " { $link f } } { "sep/f" "a character or " { $link f } } }
{ $contract "Reads characters from the " { $link stdio } " stream. until the first occurrence of a separator character, or stream exhaustion. In the former case, the separator character is pushed on the stack, and is not part of the output string. In the latter case, the entire stream contents are output, along with " { $link f } "." }
$io-error ;
2006-08-16 21:55:53 -04:00
HELP: write1
2006-01-16 02:48:15 -05:00
{ $values { "ch" "a character" } }
2006-01-17 02:43:38 -05:00
{ $contract "Writes a character of output to the " { $link stdio } " stream. If the stream does buffering, output may not be performed immediately; use " { $link flush } " to force output." }
2006-01-16 02:48:15 -05:00
$io-error ;
2006-08-16 21:55:53 -04:00
HELP: write
2006-01-16 02:48:15 -05:00
{ $values { "str" "a string" } }
{ $contract "Writes a string of output to the " { $link stdio } " stream. If the stream does buffering, output may not be performed immediately; use " { $link flush } " to force output." }
$io-error ;
2006-08-16 21:55:53 -04:00
HELP: flush
2006-01-16 02:48:15 -05:00
{ $contract "Waits for any pending output to the " { $link stdio } " stream to complete." }
$io-error ;
HELP: nl
2006-01-16 02:48:15 -05:00
{ $contract "Writes a line terminator to the " { $link stdio } " stream. If the stream does buffering, output may not be performed immediately; use " { $link flush } " to force output." }
$io-error ;
2006-08-16 21:55:53 -04:00
HELP: format
2006-01-16 02:48:15 -05:00
{ $values { "str" "a string" } { "style" "a hashtable" } }
2006-01-17 02:43:38 -05:00
{ $contract "Writes formatted text to the " { $link stdio } " stream. If the stream does buffering, output may not be performed immediately; use " { $link flush } " to force output." }
2006-01-16 02:48:15 -05:00
{ $notes "Details are in the documentation for " { $link stream-format } "." }
$io-error ;
2006-08-16 21:55:53 -04:00
HELP: with-nesting
2006-01-16 02:48:15 -05:00
{ $values { "style" "a hashtable" } { "quot" "a quotation" } }
2006-01-17 01:02:23 -05:00
{ $contract "Calls the quotation in a new dynamic scope with the " { $link stdio } " stream rebound to a nested paragraph stream, with formatting information applied." }
2006-01-16 02:48:15 -05:00
{ $notes "Details are in the documentation for " { $link stream-format } "." }
$io-error ;
2006-08-16 21:55:53 -04:00
HELP: tabular-output
{ $values { "style" "a hashtable" } { "quot" quotation } }
{ $description "Calls a quotation which emits a series of equal-length table rows using " { $link with-row } ". The results are laid out in a tabular fashion on the " { $link stdio } " stream."
$nl
"The " { $snippet "style" } " hashtable holds table style information. See " { $link "table-styles" } "." }
{ $examples
{ $code
"{ { 1 2 } { 3 4 } }"
"H{ { table-gap { 10 10 } } } ["
" [ [ [ [ . ] with-cell ] each ] with-row ] each"
"] tabular-output"
}
}
$io-error ;
HELP: with-row
{ $values { "quot" quotation } }
{ $description "Calls a quotation which emits a series of table cells using " { $link with-cell } ". This word can only be called inside the quotation given to " { $link tabular-output } "." }
$io-error ;
HELP: with-cell
{ $values { "quot" quotation } }
{ $description "Calls a quotation in a new scope with the " { $link stdio } " stream rebound. Output performed by the quotation is displayed in a table cell. This word can only be called inside the quotation given to " { $link with-row } "." }
$io-error ;
HELP: write-cell
{ $values { "str" string } }
{ $description "Outputs a table cell containing a single string. This word can only be called inside the quotation given to " { $link with-row } "." }
2006-08-16 21:55:53 -04:00
$io-error ;
HELP: with-style
{ $values { "style" "a hashtable" } { "quot" "a quotation" } }
{ $description "Calls the quotation in a new dynamic scope where calls to " { $link write } ", " { $link format } " and other stream output words automatically inherit style settings from " { $snippet "style" } "." }
{ $notes "Details are in the documentation for " { $link with-stream-style } "." }
$io-error ;
HELP: print
{ $values { "string" "a string" } }
2006-01-17 02:43:38 -05:00
{ $description "Writes a newline-terminated string to the " { $link stdio } " stream." }
2006-01-16 02:48:15 -05:00
$io-error ;
2006-01-17 01:02:23 -05:00
2006-08-16 21:55:53 -04:00
HELP: with-stream
2006-01-17 01:02:23 -05:00
{ $values { "stream" "an input or output stream" } { "quot" "a quotation" } }
{ $description "Calls the quotation in a new dynamic scope, with the " { $link stdio } " variable rebound to " { $snippet "stream" } ". The stream is closed if the quotation returns or throws an error." } ;
{ with-stream with-stream* } related-words
2006-01-17 01:02:23 -05:00
2006-08-16 21:55:53 -04:00
HELP: with-stream*
2006-01-17 01:02:23 -05:00
{ $values { "stream" "an input or output stream" } { "quot" "a quotation" } }
{ $description "Calls the quotation in a new dynamic scope, with the " { $link stdio } " variable rebound to " { $snippet "stream" } "." }
{ $notes "This word does not close the stream. Compare with " { $link with-stream } "." } ;
2006-01-17 01:02:23 -05:00
2006-08-16 21:55:53 -04:00
HELP: bl
{ $description "Outputs a space character (" { $snippet "\" \"" } ")." }
2006-01-17 01:02:23 -05:00
$io-error ;
2006-08-16 21:55:53 -04:00
HELP: write-object
2006-01-17 01:02:23 -05:00
{ $values { "str" "a string" } { "obj" "an object" } }
{ $description "Writes a string to the " { $link stdio } " stream, associating it with the object. If formatted output is supported, the string will become a clickable presentation of the object, otherwise this word behaves like a call to " { $link write } "." }
$io-error ;