Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Telix/SALT v3.15 & RS-232, Hayes - <b>functions</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
  FUNCTIONS

  A function is a way of grouping together some lines of code. A Telix
  script consists of one or more functions. There are quite a few
  advantages to having functions:

       One function can be called from another, to do a certain task.
       The calling function does not have to know anything about the
       called function other than what it does. This allows a script
       to be split up into modular units, and makes code writing and
       debugging easier.

       As mentioned above, what a function does it private. This means
       that data variables defined in a function are local to that
       function, and therefore you do not have to worry about another
       part of the script unintentionally modifying them.

       A library of functions can thus be built. Later, you do not
       have to re-write old code.

  Functions are defined in the following format:

       <funcname>(<arg1>, <arg2>, ..., <argN>)

       {
        <variable_def>
            ...
        <variable_def>

        <statement>
            ...
        <statement>
       }


  <funcname> is the name of the function. It follows the same rules of
  other identifiers in SALT. There can only be one function that uses
  a given name, however.

  <arg1> through <argN> are the declarations of the arguments
  (parameters) that have been passed to the function by its caller
  (sometimes, to accomplish its task, a function needs to have some
  values passed to it). Each argument is defined in the form <type>
  <name> where <type> is 'int' or 'str', and <name> is the name it
  should be called by. At present, a function is not allowed to have
  more than 12 values passed to it.

  <variable_def> is a variable definition, as described in the above
  section on that topic. Any number of variables may be declared at
  this part of the function. All such variables will be local vari-
  ables and available only to this function.

  <statement> is an actual line of code. There may be as many lines of
  statements in the function as needed. The format of a statement is
  described below. First though, here is an example of a complete
  function:

       max ( int a, int b )

       {

        int result;

        if (a > b)
         result = a;
        else
         result = b;

        return result;

       }

  This function returns the larger (maximum) of the two values passed
  to it. It could have been written much more simply (without the use
  of the variable), but was written this way so that all the function
  elements would be there.

See Also: structure statements

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson