Classes - stdout and stderr
The stdout
and stderr
classes provide I/O stream implementations that write to the process's standard output and standard error streams. The two classes implement the iostream API, and can be used as follows:
:- import(stdout).
:- import(stderr).
main(Args)
{
new stdout(Stdout);
Stdout.writeln("Hello World!");
new stderr(Stderr);
Stderr.writeln("Hello Error!");
Stdout.writeln("Arguments: " + Args);
}
The stdout
and stderr
classes also provide some static convenience methods which remove the need to create an object first:
:- import(stdout).
:- import(stderr).
main(Args)
{
stdout::writeln("Hello World!");
stderr::writeln("Hello Error!");
stdout::writeln("Arguments: " + Args);
}
- Parent class
- iostream
- Class members
override
canWrite()
override
flush()
override
writeByte(Byte)
override
writeString(String)
static
flush()
static
write(Term)
static
writeln(Term)
static
writeln()
static
writeTerm(Term)
static
writeTerm(Term, Vars)
- See Also
- stdin
stdout::flush()
stderr::flush()
- Description
- Flushes all data that has been written so far to standard output (or standard error).
- Examples
stdout::write("| ?- ");
stdout::flush();
Stdin.readTerm(Term);
- See Also
- write(), iostream::flush()
stdout::write(
Term)
stderr::write(
Term)
- Description
- If Term is a string, then write it directly to standard output (or standard error) without quoting.
- If Term has the form (A + B), then write A and B to the output without the plus sign. This rule is applied recursively for writing terms such as (A + B + C + ...).
- If Term is not a string or of the form (A + B), then write it using the same representation and quoting rules as writeTerm().
- Examples
Answer is 2 + 2;
stdout::write("The answer is: " + Answer);
stdout::writeln();
The answer is: 4
- See Also
- flush(), writeln(), writeTerm(), iostream::write()
stdout::writeln(
Term)
stdout::writeln()
stderr::writeln(
Term)
stderr::writeln()
- Description
- If Term is a string, then write it directly to standard output (or standard error) without quoting.
- If Term has the form (A + B), then write A and B to the output without the plus sign. This rule is applied recursively for writing terms such as (A + B + C + ...).
- If Term is not a string or of the form (A + B), then write it using the same representation and quoting rules as writeTerm().
- A newline is written after Term. If Term is omitted, then only a newline is written.
- Examples
Answer is 2 + 2;
stdout::writeln("The answer is: " + Answer);
The answer is: 4
- See Also
- write(), writeTerm(), iostream::writeln()
stdout::writeTerm(
Term)
stdout::writeTerm(
Term,
Vars)
stderr::writeTerm(
Term)
stderr::writeTerm(
Term,
Vars)
- Description
- Write Term to standard output (or standard error) in a form that is compatible with the Plang source parser for terms. The Term is not terminated with a "." or end of line marker.
- If Vars is present, then it must be a list of Name = Var declarations. If Var is encountered as an unbound variable in Term, then it will be written to Stream as Name. Variables not listed in Vars will be written as "_N", where "N" is the variable's pointer value. If Vars is not present, then all unbound variables are written as "_N". Name must be an atom or string.
- Errors
instantiation_error
- Vars is a variable.
type_error(variable_names, Vars)
- Vars is not a valid list of variable names.
- Examples
stdout::writeTerm(A - B * 1.5 + pi / 2);
produces: _1f95460 - _1f95420 * 1.5 + pi / 2
stdout::writeTerm(A - B * 1.5 + pi / 2, ["A" = A, "B" = B]);
produces: A - B * 1.5 + pi / 2
- See Also
- write(), writeln(), iostream::writeTerm()