|
»»»Home «««
»»»TELL «««
»»»Toped «««
»»»Ifaces «««
|
Table of Contents TELL has following arithmetic operators defined so far Table 1. Arithmetic operators
Operators listed above works in the expected fashion for int and real types. The same concern their order of precedence. It is more interesting to define how they work over point and box types. The behavior given in the table below is just a wild guess until better idea pops up. TELL should define a list of special operators working with those types. Not all of the operations described below are implemented. Table 2. Addition/subtraction operators with box and poly types
Table 3. Multiplication/division operators with box and poly types
Operators below are implemented for int, real and bool. For the rest of the types they are not allowed for the moment Table 4. Relational operators
Assignment operator is = and it works in the expected way. The only reminder here is that TELL maintains strict type checking. Internal silent conversion is provided only from int to real. For lists and structures assignment see variable initialization The . (dot) operator is used to access the individual fields of the build-in and user defined structures. The dot operator is applied to a variable and must be followed by a valid field name. Struct members accessed using a member operator can be used exactly as any other TELL variable. box source_area;
source_area.p1 = {0,0};
source_area.p2 = {source_area.p1.x + 2.6 , source_area.p1.y + 1.6};
struct circle { point center; real radius };
circle c1;
c1.center = source_area.p2;
c1.radius = source_area.p2.x - source_area.p1.x;Lists can be defined from any of the build-in or user types in TELL. They are homogeneous, their length is dynamic and limited only by the available memory. Empty lists are perfectly legal. One can think for TELL lists as for dynamic length arrays. It looks and works as a traditional array indexing. Indexes start at 0, thus a list of (say) 5 points will have indexes from 0 to 4. Reference to an unexisting component will trigger runtime error Invalid index. point list p1 = {{0,0},{2,0},{2,1},{1,1},{1,2},{0,2}};
point list p2 = {{100,100},{102,100},{102,101},{101,101}};
p2[0] = p1[5];
p2[1] = p1[4];
p2[2] = p1[3];
p2[3] = {100,90};A component can be added to or inserted into a list using the operators below. The symbols +: and :+ determine whether to insert before or after the target index. If target index is omitted, then they determine whether to insert the component in the beginning of the list or to add it at the end.
The examples below demonstrate the use of add/insert operator int list alst = {1,2,3,4,5};
alst[+:] = 0; // push front
//alst[+:0] = 0; // same as above
alst[:+] = 6; // push back
//alst[5:+] = 6; // same as above
alst[3:+] = 33; // insert 33 after the 3rd component
alst[+:3] = -33; // insert -33 before the 3rd componentAdd/insert operators will take also a list as an rvalue. This produces not only a simple list union, but is also capable of inserting a list anywhere into another list.
alst[3:+] = { 33, 34, 35}; // insert the list after the 3rd component
alst[+:3] = {-32,-33,-34}; // insert the list before the 3rd componentA component can be removed from the list using the following operators. Note the semantic difference with :+ operator. Here if index is given, operators :- and -: execute the same operation
echo(alst[-:3]); // remove the third component and print it echo(alst[4:-]); // remove the fourth component and print it alst[-:]; // remove the first from the list alst[:-]; // remove the last one Reduce/delete operators are removing a single component from the list. Slice operator is an extention, making possible to extract a number of consecutive components from a list.
int list blst;
echo(blst = alst[3-:]); // remove first 3 components and print them
alst[:+] = blst[:-2]; // put last 2 of them at the back of the
// original list
alst[:+] = alst[2-:]; // move first pair of components at the end
// of the list
alst[5:-2] // remove 5-th and 6-th component from the list
alst[2-:5] // remove 4-th and 5-th component from the listThe foreach loop traverses the list and sets the loop variable to each element of the list in turn. The operator syntax is similar to the corresponding perl operator.
foreach (int i; int list {5,4,3,2,1})
{
echo(i);
};This class of operators work on points. Only shift is implemented at the moment. The operation can be defined as follows
The operator has the same precedence as arithmetic addition or subtraction. Four operators are defined. The idea behind the syntax choice is that the chars constitute an angle which points in the direction of the shift. Table 6. Shift operators
Some of the cases have direct arithmetic representation and the introduction of the shift operator can be seen as a syntactics sugar Example 1. shift operators point a = {1,1};
point a1;
point a2;
point a3;
a1 = a /| 1; // will produce the same as
a2 = {a.x + 1, a.y + 1} // or
a3 = a + 1; //
//
a1 = a |/ 1; // will produce the same as
a2 = {a.x - 1, a.y - 1} // or
a3 = a - 1; //
//
a1 = a |\ 1; // will produce the same as
a2 = {a.x - 1, a.y + 1} //
//
a1 = a \| 1; // will produce the same as
a2 = {a.x + 1, a.y - 1} //
//-------------------------------------------------
point b = {1,2};
a1 = a /| b; // will produce the same as
a2 = {a.x + b.x, a.y + b.y} // or
a3 = a + b; //
//
a1 = a |/ 1; // will produce the same as
a2 = {a.x - b.x, a.y - b.y} // or
a3 = a - b; //
//
a1 = a |\ 1; // will produce the same as
a2 = {a.x - b.x, a.y + b.y} //
//
a1 = a \| 1; // will produce the same as
a2 = {a.x + b.x, a.y - b.y} //When the operator is applied to a box, only one vertex of the box is shifted - the target vertex. Depending on the operator it is top right(NE), top left (NW), bottom right(SE) or bottom left (SW) corner of the box. Example 2. shift a box point b = {1,2};
// The boxes below represent equivalent planar objects
box bx1 = {{ 1, 1}, {11,11}};
box bx2 = {{ 1,11}, {11, 1}};
// after shift the result is also equivalent planar objects
box bx1a;
box bx2a;
bx1a = bx1 /| b; // shifting the top right corner
bx2a = bx2 /| b; // of the box | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||