Sage-Code Laboratory
index<--

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.

Built IN functions:

Function Description
length return capacity of the string
count return number of true symbols and spaces except ending spaces
truncate reduce the capacity of the string to specified dimension
fill replace all characters in string with same periodic characters
erase erase all characters in a string and replace them with spaces
find search one sub-string in string
replace replace a sub-string in a string with another
parse convert a string in number
trim remove spaces from start and end of a string
left remove all spaces from left making string to align left
right remove all spaces at the right making string to align right
center move string in the middle of capacity and adding spaces left and right
indent increase string count to specified length adding spaces to the left
pad increase string count to specified length adding spaces to the right

System Library

This library is part of the language core. It is part of Eve runtime environment. Unlike standard library the system library is automatically loaded in Eve runtime environment. You do not need to import its modules.

Standard streams

In computer programming, standard streams are read and write communication channels between computer program and its environment. The three I/O connections are called standard read (stdin), standard write (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 read

Standard read is stream data (often text) going into a program. The program request data transfers by use of the read operation. Not all programs require stream read. A program may take command-line arguments, but perform their operations without any stream data read.

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

read statement Developer can create a program that ask for user to enter values from keyboard.
The read statement can output a text then wait until user type the text and press enter.

Function read declaration

read (String: prompt) => String;

Example:


process
  new v := ""; -- empty string

  read  (v, "input v:");
  write ("you entered:",v);
return;

Standard write

This is the stream where a program writes its write data. The program request data transfer with the write operation. Not all programs generate write. In this the program is silent.

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

** Function write() ** This function send a string to standard write as it is. This will help developers to make dynamic write. Is user responsibility to make a line break using an escape \n or \r inside the string parameter.


** standard routine write
routine .write(String * args, Logic:eol=True, String:sep=" "):
 ...
return;

parameters:

write sting can contain an escaped end of line character.

\LF   is LF
\CRLF is CR+LF

Usability

write function support only strings. It can not print anything else. Therefore developer must make a conversion to a string before sending the value to write.

Standard error

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

Usage

It is normal for standard write 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 write stream is line-buffered; in this , text written to standard error later may appear on the terminal earlier, if the standard write 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 write is redirected (so not readily observed). For example, write of a program in a pipeline is redirected to read of the next program, but errors from each program still go directly to the text terminal.

** example of collection iteration
module test_error:
  set this = ('a','b','c','d','e') :List;
process main
  cycle:
    new i = 0 :Integer ;
    new e :Symbol;
  while i < this.length() loop
    let e := this[i];
    let i += 1;
    if e  >= 'c' then
      write  e ;
      write ',' if e is not this.tail;
    done;
  else
    write ("i = ", i);
  repeat;
  print;
return;

Read next: Shell command