prev | next | contents


Part B: THEMATIC SUMMARY.

   Here are the various operators supported by OpenEuphoria, arranged by the type of task they help perform. A short description is provided for each of them.

1 Arithmetics and maths.

+ the ordinary addition.
- the ordinary substraction.
* the ordinary multiplication.
/ the division operator. Always returns a floating poinnt number.
- (1 operand) changes the sign of the operand.
floor(x) the greatest integer not greater than x.
ceiling(x) the smalllet integer not less than x.
remainder(x,y) a nonnegative atom, equals x-y*floor(x/y)
abs computes the absolute value of an integer or floating point number.
sqrt calculate the square root of an object
rand generate random numbers
sin calculate the sine of an angle
arcsin calculate the angle with a given sine
cos calculate the cosine of an angle
arccos calculate the angle with a given cosine
tan calculate the tangent of an angle
arctan calculate the arc tangent of a number
log calculate the natural logarithm
exp calculate the exponential of a number
power calculate a number raised to a power
PI the circle perimeter/diameter ratio (3.14159...)

2 Binary operations.

&& bitwise and
|| bitwise or
~~ bitwise xor
^ bitwise not
<< left shift
>> right unsigned shift
>>> right signed shift
and_bits(x,y) perform logical AND on corresponding bits of operands
or_bits(x,y) perform logical OR on corresponding bits of operands
xor_bits(x,y) perform logical XOR on corresponding bits of operands
not_bits(x,y) perform logical NOT on all bits of operands
rotate8| rotate16| rotate32| rotate64| rotate128(expr1,expr2)
rotates expr1, considered as a 8 (respectively 16, 32, ... bit), by expr2 positions to the right. See the detailed desription in part C below for a few size considerations.


3 array/sequence building.

{x,y,..} a nonatom whose first element is x, the second one y,...
{} an empty nonatom
"" an empty string
"..." a string
$"..."$ a long string: any line ending characters in it are ignored, so it may span several lines in source files.
"""...""" verbatim string. No processing at all is performed on a verbatim string, so line breaks are treated as is, and there are no escape sequences.
\letter an escape sequence, see part A, 2.2 for the sequences recognized.
\(number) a character whose ASCII code is number.
& concatenation (length of both operands adds up to the result's length. The second operand is considered to be of length 1 if it is an atom
r=repeat(n,x)
builds a nonatom of length n, each element of which is x.
r=append(s,x)
adds x at the end of s, length(r)=1+length(s).
r=prepend(s,x)
adds x at the beginning of s, length(r)=1+length(s).
i=length(s)
number of elements in the nonatom s.


4 sequence/array/record access

s[i] the i-th element of s
s[i..j] the sublist of s formed by its elements i through j. Empty if i=j+1 otherwise invalid.
s[i_1,...,i_n] the nonatom formed by s[i_1], ... and s[i_n].
s[i][j] the j-th element of the nonatom which is the i-th element of s
s.name the element of s with name name
.name the member in the host record with name name. Allowed only in context type statements.
s[-i] the i-th element of the mirror copy of s. Thus, s[-1] is the last element of s, and so on backwards.
cast(identifier,expr1,expr2)
sets identifier@types[expr1] to expr2, or to the routine_id of expr2. This may be needed when the known type information is better than the standard assumption and needs to be kept.

5 Assignments.

=
assigns the value on the right side to the variable on the left side.
:=
same, only in side effects of conditions
x operator= y
short for x=x operator y, where operator is any infix listed in 1 or 2.
#(x1,x2,...xn)[operator]=y
short for: x1 operator=y, x2 operator= y,...,xn operator= y. There may be no operator, hence the brackets.
#(x1,...xn)#[operator]=expr
>maps the expr on the right to the left hand side. It is short for x1 [operator]= expr[1], x2 [operator]= expr[2] and so on. Extra symbols on the left or the right are ignored. Use the _ special variable to discard the result at this place on the left.
x=get_var(expr)
gets the value of the variable of id expr.
set_var(expr1,expr2)
assigns the result of expr2 to the variable whose id is expr1.
fit(target,source,padding|_)
assigns source to target and takes appropriate action if the lengths don't match. Basically, extra elements of the left or right hand side are ignored. If target is longer than source, the remaining elements of target are set to padding, or left alone if the third eargument is _.


6 Accessing variables.

lock expr
makes the variable specified by expr (by name or by id) read-only.
unlock expr
makes a previously locked variable writeable again.
name general_identifier as identifier
creates an alias. Specially handy for accessing deeply nested subsequences.
rename general_identifier as identifier
changes an alias.
unname identifier
undefines an alias.
expr[{simpleindex}]...
specifies a part or subpart of a nonatomic entity. A simpleindex is an atom or a slice in the form expr..expr.
expr[[expr]]
The inner expr must evaluate to a nonatomic type of nonatomic type specifying parts to be extracted from the first expr.
general_identifier@identifier
the metadata with identifier the right hand operand relative to the variable on the left hand side is returned. See 5.1 in part A for a list of available metadata.

7 Relational operators.

= is equal to
!= is not equal to
<,<= is less than, is no greater than
>,>= is greater than, is not less than
x and y is true if and only if x and y are true.
x or y is true whenever x or y is true
not x true if x is false, false if x is true.
x=compare(expr1,expr2)
compares expr1 to expr2, and returns -1 (less), 0 (equal) or 1 (greater). For this porpose, an atom is always less than a nonatom.
x=equal(expr1,expr2)
equivalent to x=(compare(expr1,expr2)=0)

8 Declaring variables/types.

[global ]type {identifier[=expr]}
declares all identifiers in the nonempty list on the right to be variables of the type type. If the global keyword is used, they may be seen from other files. It is disallowed inside routines. The identifiers may get an initial value on declaration.
[static ]type {identifier[=expr]}
declares all identifiers in the nonempty list on the right to be variables of the type type. If the "static" keyword is used, they will persist between two invocations of the current routines. This form is allowed only in routines, and may not follow general code statements. Symbols may get an initial value on declaration.
[global ]constant {[type ]identifier=expr}
defines constants, which are symbols whose value does not change and is specified on declaration. Their types may be specified. If not, object is assumed. Using the keyword global may make the symbols to be seen from outside the file they are defined in; it cannot be used in routines.
new_var(type,name,value|_)
creates a new variable of the type type, with name name, and initial value the third argument. If this argument is '_', no initial value is assigned.
del_var(expr)
destroys a variable that was created using new_var().
id(expr)
if expr evaluates to a string, returns the id of the only visible variable with this name, or -1 if none.
var(expr)
if exppr evaluates to a string, returns the name of the variable with this id, or "" if none.
[check ][global ][forward ]type name(type identifier)
specifies a routine to be called whenever a variable of that type is being assigned and type is checked. This defines an user-defined type. Types must return a boolean, and take exactly one argument.
[check ][global ][forward ]reftype name(integer identifier,type identifier)
specifies a routine to be called whenever a variable of that type is being assigned and type is checked. This defines an user-defined type. The first argument of this routine is a variable id, and the second is the value to be assigned. reftypes must return a boolean.
array(expr) [of type]
an ordered, indexed collection of expr elements passing the same type check. The object type is assumed if no type is provided.
sequence [of type]
an ordered, indexed collection of elemnts passing the same type check. The object type is assumed if no type is supplied.
record identifier({type|_ identifier|_)} ... end record
a collection of elements, each of them with a type and a name. The elements can be accessed by name or index (their rank in the order in which they were enumerated). An element may have no name; an unnamed type will be defined later as a contxt type (see part A, 1.4).
is
The construct type | reftype altname is aliased allows to define an alias for the type aliased. This is specially useful as it is the only way to call the type checking function for a compound type such as "sequence of integer".

9 Including abstract files.

include filename|(expr) [as namespace]
makes all global symbols from filename be seen in the default namespace as well as in the specified namespace if any. If filename is included or imported for the first time in a program, its top level statements are executed. Using parentheses allows to use an expression rather than an explicit filename.
import filename|(expr) as namespace
makes all global symbols from an abstract file visible in namespace. If filename is included or imported for the first time in a program, its top level statements are executed. The global symbols in filename do not appear in the default namespace. The filename may be computed, as for the include statement.
promote [but] symbol list from namespace
makes the specified symbols in namespace available in the default namespace. The list may be implicit or explicit, in which case it must appear between double quotes. You can define in this way the list of symbols not to be visible in default. Using '_' means all symbols.
demote [but] symbol list [from namespace]
makes the specified symbols unavailable in the default namespace. The list may be implicit or explicit, in which case it must appear between double quotes. You can define in this way the list of symbols not to be visible any longer in default. The from clause is mandatory if but is used. Using '_' means all symbols.
[global ]scope [name] ... end scope
defines an area of code which can be seen from the outside under certain conditions, and from where the default namespace can't be seen without an explicit prefix. The name may be used as a namespace prefix. See chapter 7 in part A for more details.
use name
allows a given area of code to access the global symbols of a scope named name using the name as a namespace prefix. The area of code can be either the top level code of a file, a scope or a routine.

10 Instruction flow control.

if cond then
starts an if block. If cond is true, executes until next elsif/else (exclusive), or end of block if there's none. Jumps to the next elsif/else otherwise, or out of the block if there's none.
elsif cond then
same as if, but only inside an if block.
else
allowed only in an if block. Executes until the end of the if block, because no if/elsif cond was true.
exif [number|identifier]
jumps out of the specified if block. See part A, 9.5, for details of exited block specification.
select expr
prepares to cexecute statements conditionally to the value of expr. This value is called selector, and is not computed again inside the block.
case expr:
executes if selector equals to expr. There should be no isolated "_" in expr.
case cond:
isolated "_" in cond are repleced by the selector value. Then, cond is evaluated, and the case branch executes if and only if this value is True.
case relational expr:
short for case _relational expr:
case expr1 thru expr2:
short for case expr1<=_<expr2:
stop
jump out of the current case branch.
break [identifier|number]
jump out of the designated select block. See part A, 9.5, for details of exited block specification.
otherwise
executes statements to the end of select block, if no case branch in the current select block was taken.
for index=start value to end value [by increment] do
starts a for loop block. index is the for loop index variable; it must not be declared. All these are evaluated only once. If there is no increment, +1 is assumed. The loop iterates until index is out of bounds. No iteration occurs if index cannot reach end value from start value by adding some number of incremênt.
wfor index=start value to end value [by increment] do
starts a wfor loop block. This is the same as a for loop, except that the index variable must be declared, and that start value, end value and increment are computed at each new loop iteration.
while cond do
starts a while loop. The loop iterates until cond is no longer true.
end block name
ends a block. The block name must match the opening block name.
label identifier
tags a code block. This tag may be used as an argument of exit, exif, break, next and retry.
exit [number|identifier]
jumps out of the specifiedloop loop.
next [number|identifier]
starts the next iteration of the specified loop immediately.
retry [number|identifier]
restart the current iteration of the specified loop immediately.

11 Nonatomic types manipulations.

reverse(expr)
returns a nonatom which is the reversed image of expr: first element beccomes last, second element becomes second last,...,last element becomes first.
move(target,start,end,where)
returns a nonatom of the same length as target. It is obtained from target by moving the slice target[start..end] so that it starts at where. If this causes the slice to extend past the size target had, an error occurs.
find(what,where)
returns the position of the first occurrence of what as an element in the nonatom where, or 0 if none is found. This position may not be the index of an element of where if where has subsequences as elements.
match(what,where)
returns the first occurrence of what as a part of where, or 0 if none is found.
find_all(what,where)
returns the sequence of the positions of all occurrences of what as an element in the nonatom where, or {} if none is found.
match_all(what,where)
returns the sequence of all occurrences of what as a part of where, or {} if none is found.
insert(target,places,items)
returns a sequence which is target in which where the elements of items have been inserted in the positions defined by places.
insert_sequence(target,places,items)
returns a sequence which is target where the elements of items have been inserted as subsequences at the positions specified in places.
remove(target,places)
returns a sequence which is target with elements specified in places removed.
replace(target,places,items)
returns a sequence which is target where the subsequences specified by places were replaces by the elements in items.
rotate(target,start,end,number)
rotates target[start..end] by number positions to the right. number may be negative in order to rotate the slice to the left.
 

12 Dynamic code execution.

call_func(expr,list)
calls the function with routine_id expr using the list of arguments list, which may be {}. Evaluates to whatever that function returns.
call_proc(expr,list)
calls the procedure with routine_id expr using the list of arguments list, which may be {}. No return value is expected.
call_routine(expr,list)
calls the routine with routine_id expr using the list of arguments list, which may be {}.
execute(expr)
if expr evaluates to a string, executes the statement(s) contained in this string.
routine_id(expr)
expr must evaluete to a string. The id of the visible routine with this name is returned, or -1 if none.
get_name(expr)
expr must evaluate to an integer, and the name of the routine with this id is returned, or "" if none.
resume_execute(expr)
returns from curent handler, execute()s the argument and then possibly acts as resume would.
return_execute(expr)
returns from curent handler, execute()s the argument and then possibly acts as return would.

13 Defining and calling a routine

[global ][forward ]routine type routine name({[update ] [type ]name})
declares a possibly global routine, of the type routine type, and with name routine name. The possibly empty parameter list contains formal parameters. A formal parameter has one to three compnents:
  • an optional update keyword, which states that the argument mapped to this formal parameter is to be passed by reference. If this keyword is absent, the argument will be passed by value;
  • the parameter type. It is assumed to be equal to the type of the previous parameter if not supplied.
  • the mandatory parameter name

Making the routine global may make it visible elsewhere in the program.
Using the forward keyword means that the routine statements do not immediately follow.
The known routine types are: routine, function, procedure, type, reftype and handler.
routine type routine name
this short form immediately precedes the statements of a routine that was declared as forward.
routine name({[attr ]expr})
invokes the routine routine name and passes it its possibly empty argument list. When a formal parameter was declared using the update keyword, and the corresponding argument is a posssibly indexed variable, an attr must be provided. attr has two possible values: byval if parameter is to be passed by value, byref if the parameter is to be passed by reference. byval may be used to emphasize that the argument is to be passed by value, even when this is bound to happen anyway.

14 Miscellaneous.

get_meta("name"|expr)
returns a record containing the metadata for the argument. The argument is either a double quoted symbol name or an expression evaluating to an id. The type of the returned value is either SystemVarMeta or SystemRtMeta, according to whether the argument refers to a variable or to a routine. See 5.1 and 8.8 in part A for a description of the metadata.
isvarid(id)
returns True if id is the id of a variable, and False otherwise. Remember that ids are never recycled, so that a stored id may be invalid if one os not careful enough.
analyze_id(id)
returns a triple {name,index,parent}. name is any name the variable or nonatom element has. index is 0 for variables, and the index of the element referred to in the sequence it is an element of. parent is the id of that sequence if it exists, or id otherwise.
return [expr]
stops executing a routine and, if an optional argument is provided, returns the value it evaluates to.
set_handler(expr,expr)
set the handler for events listed in the first expr as the routine with id the second expr.
get_handler(expr)
returns the id of the handler for the event name expr evaluates to. Returns -1 for an unknown event.
error(expr)
raises a mostly fatal error. expr must evaluate to a string, and that string is displayed as an error message at crash time.



prev | next | contents