Input & Output

Atomo uses an I/O system similar to Scheme - methods for reading/writing internally use current-input-port or current-output-port, which can be overridden via parameterization. Certain methods, e.g. print and read-line, will act on whatever those parameters are.

Port  Object

An object to read/write to. Typically has one slot, handle, which points to the file descriptor (a Haskell Handle).

Port new: filename &mode: @read-write  Port
  | filename is-a?: String
  | [@read, @write, @read-write, @append] contains?: mode

Open the file filename and return a Port for performing I/O.

Port standard-input  Port

Standard input port (stdin).

Port standard-output  Port

Standard output port (stdout).

Port standard-error  Port

Standard error port (stderr).

p print: v  v
  | p is-a?: Port
  | v responds-to?: @(as: String)

Outputs v as: String to p, followed by a linebreak.

p display: v  v
  | p is-a?: Port
  | v responds-to?: @(as: String)

Outputs v as: String to p.

p read  any
  | p is-a?: Port

Reads a primitive value from p. A primitive value is an integer, double, character, string, or lists and particles that contain primitive values. For anything else, if the parse is successful it returns it as an Expression. This includes blocks an arbitrary paranthesized expressions, or lists/particles containing non-primitives.

The idea is that any value returned by read is safe; anything else is returned unevaluated.

p read-line  String
  | p is-a?: Port

Read a line of text from p.

p contents  String
  | p is-a?: Port

Read in p's entire contents, blocking until the end of the input is reached.

p flush  @ok
  | p is-a?: Port

Flush p's output. print and display automatically perform this task for you.

p close  @ok
  | p is-a?: Port

Close p, flushing any output.

Parameters

current-output-port  Parameter

A Parameter containing the default port used for printing output.

Default is Port standard-output.

current-input-port  Parameter

A Parameter containing the default port used for getting input.

Default is Port standard-input.

o print  o
  | o responds-to?: @(as: String)

Outputs o as: String to current-output-port, followed by a linebreak.

o display  o
  | o responds-to?: @(as: String)

Outputs o as: String to current-output-port.

read  o

Reads an object from current-input-port.

read-line  String

Reads one line of text from current-input-port.

with-input-from: p do: action  any
  | (p is-a?: Port) || (p is-a?: String)
  | a is-a?: Block

Parameterize current-input-port and execute action, returning its result.

If p is a String, it is considered a filename, and that file is opened for reading. The file is automatically closed after the block's execution.

If p is a Port, it is used for input.

with-output-to: p do: action  any
  | (p is-a?: Port) || (p is-a?: String)
  | a is-a?: Block

Parameterize current-output-port and execute action, returning its result.

If p is a String, it is considered a filename, and that file is opened for writing. The file is created if it doesn't exist, or overwritten if it does. The file is automatically closed after the block's execution.

If p is a Port, it is used for output.