Changes between Version 7 and Version 8 of Doc/panc/dml/functions


Ignore:
Timestamp:
Mar 3, 2007, 5:04:19 PM (17 years ago)
Author:
/O=GRID-FR/C=FR/O=CNRS/OU=LAL/CN=Charles Loomis
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Doc/panc/dml/functions

    v7 v8  
    44== Calling Functions ==
    55
     6Within a Data Manipulation Language (DML) block, user-defined and built-in functions may be called.  The pan language uses a typical syntax for calling a function:
     7{{{
     8identifier(arg1, arg2, ...);
     9}}}
     10where 'identifier' is a valid pan identifier and the arguments are passed to the function as a comma-separated list.  The arguments may be expressions, in which case those expressions will be completely evaluated before calling the function.
     11
     12All functions return a value, although it might be 'undef'.
     13
    614== User-Defined Functions ==
     15
     16The pan language permits user-defined functions.  These functions are essentially a DML block bound to an identifier.  Only one DML block may be assigned to a given identifier.  Attempts to redefine an existing function will cause the execution to be aborted.  The syntax for defining a function is:
     17{{{
     18function identifier = DML;
     19}}}
     20where identifier is a valid pan identifier and DML is the block to bind to this identifier.
     21
     22When the function is called, the DML will have the variables 'ARGC' and 'ARGV' defined.  (The deprecated names 'argc' and 'argv' will also be defined.)  The variable 'ARGC' contains the number of arguments passed to the function; 'ARGV' is a list containing the values of the arguments.
     23
     24The pan language does no automatic checking of the number or types of arguments.  The DML block that defines the function must make all of these checks explicitly and use the error() function to emit an informative message in case of an error.
     25
     26Recursive calls to a function are permitted.  However, the call depth is limited (by an option when the compiler is invoked) to avoid infinite recursion.  Typically, the maximum is a small number like 10. 
     27
     28The following example defines a function that checks if the number of arguments is even and are all numbers:
     29{{{
     30function even_numbers = {
     31
     32  if (ARGC%2 != 0) {
     33    error('number of arguments must be even');
     34  };
     35
     36  foreach (k, v, ARGV) {
     37    if (! is_number(v)) {
     38      error('non-numeric argument found');
     39    };
     40  };
     41}}}
     42
    743
    844== Built-In Functions ==