Standard Library

This is a library that is imported by default into the language. We do not have to use import. It contains built-in functions that can be implemented in Eve or in other language. The only thing required is signature. The modules that connect a program to the machine are in the System Library.

Built-in names

These names need no import and no library file: the virtual machine provides them. A later version may write some of them in a library module that the machine loads on its own; the names and these rules do not change when that happens.

NameFormMeaning
printstatement print a, b;write the arguments separated by sep (a comma by default), then a new line
writestatement write a, b;write the arguments with no separator and no new line
readfunction read(prompt)write the optional prompt, read one line and give it as a String without its line end; null at the end of the input
errorfunction error(text)write a line on the standard error and go on
warningfunction warning(text)the same, for a warning
log_errfunction log_err(text)add an error line to the run log of the process (recover region)
log_wrnfunction log_wrn(text)the same, for a warning
raisestatementraise the error $error and leave the region
expectstatementcheck a condition; a failure ends the process with error code 2
assertstatementcheck a condition; a failure ends the process with error code 3

The error of the process is $error, with the fields code, message, line and job; the codes are the constants $err_name and $wrn_name. Error classes with fields, recover by type and a function warn belong to typed exceptions and are not part of the built-in names yet.

Other functions are not built in: they belong to a module of the System Library or to a value. The value functions of strings and collections are listed with their status in Strings and Collections; some are still being completed.

Standard streams

In computer programming, standard streams are input and output communication channels between a computer program and its environment. The three I/O connections are called standard input (stdin), standard output (stdout) and standard error (stderr). These channels are connected to the program when program starts.

When a program is executed via an interactive shell, the streams are typically connected to the text terminal on which the shell is running, but can be changed with redirection, using a pipeline.

Standard input

Standard input is stream data (often text) going into a program. The program requests data with the read procedure. Not all programs require standard input. A program may take command-line arguments, but perform its operations without any stream data.

Unless redirected, standard input is expected from the keyboard which started the program.

read lets a program ask the user to enter a value from the keyboard. It writes the prompt, waits until the user types a line and gives that line as a String, without its line end. At the end of the input it gives null, so a loop can test it. It is a function, not a procedure.

read(prompt: String) => (String?);

Example:


process main is
  new line := read("input v: ");
  if line <> null then
    print "you entered:", line;
  else
    print "no input";
  done;
return;

Standard output

This is the stream where a program writes its output data. The program requests the transfer with the write and print procedures. Not all programs generate output; then the program is silent.

Unless redirected, standard output is the text terminal which initiated the program.

print sends its arguments to standard output, separated by sep, and ends with a new line. write sends them with no separator and no new line. Both are statements; they have no result. print; alone ends the line that write started.

print a, b, sep: " ";
write a, b;

parameters:

  • a, b: the values to send, any number of them; each value is written as it is, so print 1 + 1; writes 2;
  • sep: the text put between two arguments; it is a comma for print and nothing for write; sep: " " separates them by a space. It works only between several arguments: a list given as one argument is printed as a list, (1,2,3), whatever sep is.

A string can contain escapes. A backslash escapes the next character, \\ is one backslash, and &code; sends any HTML character code, such as &lt; or &#955;. The end of line is written \n.

Usability

print and write write every value: a number, a logic value, a collection, an object. A string placeholder {x} converts a value inside a text; the functions do the same when they write it. A format such as {x:5} sets the width and the alignment.

Standard error

Is another output stream typically used by programs to write error messages or diagnostics. It is a stream independent of standard output and can be redirected separately.

Usage

It is normal for standard output and standard error to be directed to the same destination, such as the text terminal. Messages appear in the same order as the program writes them, unless buffering is involved.

For example, a common situation is when the standard error stream is un-buffered but the standard output stream is line-buffered; in this , text written to standard error later may appear on the terminal earlier, if the standard output stream buffer is not yet full.

Redirect

The usual destination is the text terminal which started the program to provide the best chance of being seen even if standard output is redirected (so not readily observed). For example, the output of a program in a pipeline is redirected to the input of the next program, but errors from each program still go directly to the text terminal.

Procedures

Two procedures output text to stderr, error() and warning(). Two more, log_err() and log_wrn(), are for the recover region of a process: they do not print, they append the message to a log file in the output folder ($EVE_OUT, out by default).

procedure error(message: String);
procedure warning(message: String);
procedure log_err(message: String);
procedure log_wrn(message: String);

When a primary aspect ends with an unhandled error, Eve writes the last error to stderr: the message with the call stack in debug mode, only the message otherwise.

The functions error and warning add the text "Error:" and "Warning:" before the actual message. They use same buffering as the print and write. This is to avoid interlacing messages on stdout when stdout is not redirected.

** example of error and warning
process main is
  print "Test start";
  error("This is an error");
  warning("this is a warning");
  raise {code: 200, message: "test error"};
finalize
  print "Test end";
return;

Read next: System Library