Readers and Writers
Readers
- Any stream of input data is called a Reader in Slag.
- This philosophy pervades the language - for example, lists, ranges, strings, and files may all have create_reader() called on them to produce a reader of the appropriate type.
- An object that can create a Reader object is called a Readable object and should incorporate the Readable<<DataType>> aspect.
- Given an object that is a Reader<<DataType>>, Slag defines "read" as "to extract one unit of the given DataType". If you have a Reader<<Char>>, you know that calling read() on it will return a single Char value.
- The forEach loop automatically works with any Reader or Readable object, setting the loop counter to be each value read (after potentially calling create_reader()). See advanced forEach loops for an example of creating a custom reader.
| Readable<<DataType>> underlying aspect : ReadableType |
|
| Reader<<DataType>> underlying aspect : ReaderType, ListAdaptable<<DataType>> |
|
| StandardReader<<DataType>> underlying aspect : Reader<<DataType>> |
|
| TextReader aspect : Reader<<Char>> |
|
Writers
- Any object that may have data written to it is called a Writer. A Writer that can write Int32 values is a Writer<<Int32>>.
- An object that can create a Writer object is called a Writable object and should incorporate the Writable<<DataType>> aspect.
- To write() means to output a single unit of the writer's fundamental data type. To print() means to convert various types of information into text form.
- A TextWriter is a Writer<<Char>> with numerous print() methods for printing different data types.
- The most often used writers in Slag are the StringBuilder and the FileWriter, both of which extend TextWriter (see the sections on Strings and Files).
| Writable<<DataType>> underlying aspect |
|
| Writer<<DataType>> underlying aspect |
|
| TextWriter class : Writer<<Char>> |
|
- Login to post comments
