## 5 Programming ¶

### 5.1 Input and Output ¶

#### Input commands ¶

`read s`

  Opens the file whose name is string s for reading.

`close`

  Closes the previously opened data file.

Standard input is used unless a data file is specified at command line invocation or open for reading.

#### Input functions ¶

`number(s)`

  Reads a number from current input.

`string(s)`

  Reads a string from current input.

String s is used as a prompt.

Example:

    l = number("Length? ")
    w = number("Width? ")
    draw rectangle(l, w)

When running in batch mode with no defined data file, the `number` function returns 0 and the `string` function returns the empty string.

#### Output commands ¶

Output commands take a comma separated list of printable objects as arguments. Printable objects are strings, numbers, points and sets. They are formatted the same way as for conversion to string.

`write s`

  Opens the file whose name is string s for writing. If the file exists, its content will be overwritten. Otherwise, it is created.

`append s`

  Opens the file whose name is string s for appending. The file is created if it does not exist. Writing starts at the end of the file.

`release`

  Closes previously opened result file.

`print list`

  Writes list to current result file, or to standard output if none is open.

`error list`

  Writes list to standard error stream.

`output list`

  Writes list to output file. This may be useful to include low level PostScript or PSTricks command invocations.