»»»Home «««
Framework
Screenshots
FAQ
»»»TELL «««
Types
Operators
Functions
Example
»»»Toped «««
Database
Cells
Add
Select
Edit
View
Interfaces
Miscellaneous

Functions

Functions are the basic building blocks of TELL code. Syntactically they look like C code. Below is the list of the main properties of TELL functions

  • Functions can be prototyped
  • There is no main functions as in C. Instead code is allowed outside function boundaries as described in the introduction
  • Functions can be overloaded as long as their type remains fixed.
  • Functions accept arguments and return a value. void keyword is predefined to allow a definition of the function that does not return anything.
  • Functions can be called recursively.

The example below demonstrate the function definition and function call.

   box MOStran(point bound, real W, real L) {
      // draw some shapes
      return {{0,0},{10,8}}; // overlapping box
   }

   void Invertor(point bound, real NW, real NL, real PW, real PL) {
      MOStran(bound,NW,NL);
      // doing something
      box ptrActive = MOStran(bound,PW,PL);
   }

The examples of overloaded functions are Toped build-in functions like addbox, addpoly etc. described later in this manual.

[Warning]Warning

Some overloaded definitions may be ambiguous. If a function is called with anonymous arguments, and more than one of the definitions match the argument list, the result of the call is undefined. Here is an example:

   struct same_as_point {real a; real b};

   function ambi (point A) {
      echo("Input argument of type point);
      // do something
   }

   function ambi (same_as_point A) {
      echo("Input argument of type same_as_point);
      // do something
   }

   point P = {1,1};
   ambi({1,1}); // ambiguous call, any of the overloaded functions
                // can be called
   ambi(P);     // OK, because P is of a known type

The parser is not flagging this type of errors yet.

Recursive function call

Here is a quick example of a function calling itself

int factoriel(real stop)
{
   if (stop > 0)
   {
      int inter = factoriel(stop - 1);
      return (stop * inter);
   };
   return 1;
}

top

Library functions

TELL itself hardly defines any build-in functions. Toped however internally defines and implements a list of functions ensuring its own functionality. In general the editor that interprets TELL must define and implement its own internal functions. These functions will be parsed first as a part of the initialization phase of the interpreter, so that any internal commands (function calls) received from the command line (or file) can be properly handled.

length

Returns the list length. Empty lists are valid and their length will be 0

[Tip]int length( llst )
<any> list llst
input list

Example 1. length

   int list b;
   echo(length(b));

top

abs

Returns the absolute value of the argument. Because of the internal conversion between int and real, the function works for both types.

[Tip]real abs( arg )
real arg
input argument

Example 2. abs

   int a = -3;
   int b = abs(a);
   real ra = -3.33;
   real rb =  3.33;

top

sin

Returns the sine of the argument. The value of the argument must be in degrees

[Tip]real sin( arg )
real arg
input argument

Example 3. sin

   point list arc(point center, int radius, int start, int stop, int numsteps)
   {
      real step = abs(stop -start) / numsteps;
      real current = start;
      point list the_arc;
      while (current <= stop)
      {
         point cur_point;
         cur_point.x = center.x + radius * cos(current);
         cur_point.y = center.y + radius * sin(current);
         current = current + step;
         the_arc[:+] = cur_point;
      }
      return the_arc;
   }

top

cos

Returns the cosine of the argument. The value of the argument must be in degrees

[Tip]real cos( arg )
real arg
input argument

See the example in sin

top

echo

Prints the value of a TELL variable. This function is rather temporary. It takes any type of argument and prints its value in the log window. It could be useful for some very basic debugging of the TELL script.

[Tip]void echo( variable )
<any_type> variable
A variable of any valid TELL type.

Example 4. echo

   echo("Welcome");
   point list triangle{{0,0},{1,2},{3,4}};
   echo (triangle);

top