»»»Home «««
»»»TELL «««
»»»Toped «««
»»»Ifaces «««
|
Table of Contents The operators listed below work in the expected fashion for int and real types. The same is true for their order of precedence. Table 1. Arithmetic operators
See planar operators for further definitions of those operators with point and box operand types. Operators below are implemented for int, real and bool. For the rest of the types they are not allowed. Table 2. 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; See list types 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}; In addition to the traditional indexing, Tell defines also index
range operator int list l1 = {0,1,2,3,4,5}; int list l2 = l1[2:4]; // Index range echo(l2); // shall produce: list members: { 2 , 3 , 4 } echo(l1[2:4]); // this shall report the same A component can be added to or inserted into a list using the operators below.
The symbols
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 component Add/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 component A component can be removed from the list using the following operators. Note the
semantic difference with :+ operator. Here if index is given,
operators
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 list The 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 works on points and boxes. The tables below define the accepted operands for each operator. Table 4. Subtraction operator with box and poly types
Table 5. Multiplication operator with box and poly types
Table 6. Division operator with box and poly types
This operation can be invoked with almost any combination of box , point and int/real operands as described in the + and - tables above. The result always takes the type of the more complex operand. As the name suggests it shifts the location in the plane of the more complex operand. /* This example lists all cases of shift */ real r = 10; point p = {1,2}; box b = {{1,2},{3,4}}; //Point and scalar echo(p+r); // {X = 11, Y = 12} echo(r+p); // {X = 11, Y = 12} echo(p-r); // {X = -9, Y = -8} echo(r-p); // error - unexpected operand type // point and point echo(p+p); // {X = 2, Y = 4} echo(p-p); // {X = 0, Y = 0} // box and point echo(b+p); // {{X = 2, Y = 4}, {X = 4, Y = 6}} echo(p+b); // {{X = 2, Y = 4}, {X = 4, Y = 6}} echo(b-p); // {{X = 0, Y = 0}, {X = 2, Y = 2}} echo(p-b); // error - unexpected operand type The operation works on a box and produces a new enlarged box /* This example lists all cases of blow */ real r = 10; box b = {{1,2},{3,4}}; // box and scalar echo(b+r); // {{X = -9, Y = -8}, {X = 13, Y = 14}} echo(r+b); // {{X = -9, Y = -8}, {X = 13, Y = 14}} Pretty much the same as blow, but simply modifies the box in the opposite direction /* This example lists all cases of shrink */ real r = 1; box b = {{1,2},{3,4}}; // box and scalar echo(b-r); // {{X = 2, Y = 3}, {X = 2, Y = 3}} echo(r-b); // error - unexpected operand type /* This example lists all cases of scale */ real r = 10; point p = {1,2}; box b = {{1,2},{3,4}}; //Point and scalar echo(p*r); // {X = 10, Y = 20} echo(r*p); // {X = 10, Y = 20} echo(p/r); // {X = 0.1, Y = 0.2} echo(r/p); // error - unexpected operand type // box and scalar echo(b*r); // {{X = 10, Y = 20}, {X = 30, Y = 40}} echo(r*b); // {{X = 10, Y = 20}, {X = 30, Y = 40}} echo(b/r); // {{X = 0.1, Y = 0.2}, {X = 0.3, Y = 0.4}} echo(r/b); // error - unexpected operand type In addition to the above operators Tell defines another set of operators for convenience.
This class of operators 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 8. Directional shift operators
Some of the cases have direct arithmetic representation and the introduction of the shift operator can be seen as a syntactic sugar Example 1. shift a point 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; // (shift) // a1 = a |/ 1; // will produce the same as a2 = {a.x - 1, a.y - 1} // or a3 = a - 1; //(shift) // 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; // (shift) // a1 = a |/ b; // will produce the same as a2 = {a.x - b.x, a.y - b.y} // or a3 = a - b; // (shift) // a1 = a |\ b; // will produce the same as a2 = {a.x - b.x, a.y + b.y} // // a1 = a \| b; // 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 |