Refal-5 includes a library of standard built-in functions. These include I/O and arithmetic operations, various system jobs which cannot be defined in Refal, and some simple procedures which are built into the system for greater efficiency. If need be, a function name used for a built-in function can be reassigned to denote a function defined in Refal. The built-in function will then be inaccessible.

<Card>

returns (is replaced by) the next line from the input. Normally it is from the terminal, but input can be redirected as allowed by MS-DOS. The returned expression is a sequence of character-symbols (possibly empty). The End-Of-Line byte is not included. If the input is read from a file, the macrodigit 0 is returned when the end of file is reached (no more lines). This is used in programs as the indicator of end, since a macrodigit cannot result from input otherwise. When reading from the terminal, enter Control-Z to produce the same effect.

<Print e.Expr>

prints the expression ** e.Expr** on the current
output and returns (is replaced by)

<Prout e.Expr>

prints the expression ** e.Expr** on the current
output and returns the empty expression.

Functions that work with files require a file descriptor as an argument. A file descriptor is a macrodigit in the range 1-19; in some operations the descriptor 0 is allowed and refers to the terminal.

<Open s.Mode s.D e.File-name>

opens file ** e.File-name** and associates it with
the file descriptor

<Get s.D>

where ** s.D** is a file descriptor or , is similar
to

<Put s.D e.Expr>

where ** s.D** is a file descriptor or , writes

<Putout s.D e.Expr>

returns empty (like ** Prout** ). In all other
respects

*Representation* *of* *numbers*. Whole numbers
are represented as sequences of *macrodigits* using the base
2^{32} . Negative whole numbers are preceded by the
character ** '-'** . Positive numbers may be preceded
by

Real numbers (of either sign) are represented as single symbols and take a 32-bit word. (For the syntax of real numbers see Reference Section B.)

The basic format of binary arithmetic operations is:

<ar-function(e.N1) e.N2>

However, the parentheses can be dropped. This is no problem with real numbers, since each of those takes exactly one symbol. When the first argument is a whole number, it will be assumed to take one macrodigit possibly preceded by a sign, while the rest goes to the second argument.

If both arguments of an arithmetic function are whole numbers, the result is also a whole number; otherwise it is a real number.

The following functions *ar*-*function* are
implemented:

** Add** or

returns the sum of the operands.

** Sub** or

subtracts

** Mul** or

returns the product of the operands.

** Div** or

if at least one argument is real, returns the real quotient. If both are whole,

`Divmod`

expects whole arguments and returns

(e.Quotient) e.Remainder

The remainder is of the sign of ** e.N1** .

`Mod`

expects whole arguments and returns the remainder of the division
of ** e.N1** by

`Compare`

compares the two numbers and returns ** '-'** if

`<Trunc eN>`

where ** eN** is a real number, returns the truncated
whole number.

`<Real eN>`

where ** eN** is a whole number, returns the equal
real number.

** <Realfun (e.Function) sN>** or

returns the value of the function

`<Br e.Name'=' e.Expr>`

*buries* (see Chapter 4) the expression ** e.Name**
under the name

`<Dg e.Name>`

*digs* the expression buried under the name ** e.Name**
, i.e., returns the last expression buried under this name and
removes it from the stack. If there is no expression buried under

`<Cp e.Name>`

works as ** Dg** but does not remove the expression
from the stack.

`<Rp e.Name'=' e.Expr>`

replaces the expression buried under the name ** e.Name**
by

** <Dgall>** digs out the whole stack. The
stack is a string of terms of the form

(e.Name'=' e.Value)

Each time ** Br** is activated, such a term is
added on the left side.

`<Type e.Expr>`

returns ** s.Type e.Expr** , where

s.Typestarts withe.Exprletter'L'digit'D'identifier or function name'F'macrodigit'N'real number'R'any other symbol'O'left parenthesis'B''*'is emptye.Expr

`<Numb e.Digit-string>`

returns the macrodigit represented by ** e.Digit-string**
.

`<Symb s.Macrodigit>`

is the inverse of ** Numb** . It returns the string of
decimal digits representing

`<Implode e.Expr>`

takes the initial alphanumeric characters of ** e.Expr**
and creates an identifier (symbolic name) from them. The initial
string in

`<Explode s.Identifier>`

returns the string of character-symbols which make up ** s.Idenitifier**
.

`<Chr e.Expr>`

replaces every macrodigit in ** e.Expr** by the
character-symbol with the same ASCII code modulo 256.

`<Ord e.Expr>`

is the inverse of ** Char** . It returns the
expression in which all characters are replaced by macrodigits
equal to their ASCII codes.

`<First s.N e.Expr>`

where ** s.N** is a macrodigit, breaks up

`<Last s.N e.Expr>`

is similar to ** First** but it is

`<Lenw e.Expr>`

returns the length of ** e.Expr** in terms followed by

`<Lower e.Expr>`

returns the original expression ** e.Expr** in which
all capital letters are replaced by lower case letters.

`<Upper e.Expr>`

is similar to ** Lower** . All lower case letters are
capitalized.

`<Step>`

returns the sequential number of the current step as a
macrodigit.

`<Time>`

returns a string containing the current system time.

`<Arg s.N>`

where ** s.N** is a macrodigit, returns the command
line argument which has the sequential number

** <Mu s.F-name e.Expr>**
, or

finds the function whose name is

<Implode e.String>

(when given in the form of a string of characters) and applies
it to the expression ** e.Expr** , i.e., is replaced
by

upgrades ** e.Expr** (demetacodes it). See Chapter 6 for
restrictions on

** <Dn e.Expr>**
downgrades