    [NAME]
    ALL.dao.routine

    [TITLE]
    Routine

    [DESCRIPTION]

    Routine is a block of codes, once defined, can be used in different places at different
    time repeatedly. It can accept parameters to changes its behaviour. It may also return
    results to its callee.

    Dao routines are declared with keyword routine or function or sub (which are exactly
    equivalent to routine),

       1  routine func( a, b )
       2  {
       3     io.writeln( a, b );
       4     a = 10;
       5     b = "test";
       6     return a, b; # return more than one results.
       7  }
       8
       9  r1, r2;
      10  ( r1, r2 ) = func( 111, "AAA" );
      11  r3 = func( r1, r2 );
      12  io.writeln( "r1 = ", r1 );
      13  io.writeln( "r2 = ", r2 );
      14  io.writeln( "r3 = ", r3 );

     0.1  Named Parameter

    In Dao the function parameters are named, and parameter values can be passed in by name:

       1  func( b => 123, a => "ABC" );

     0.2  Parameter Type and Default Value

    It is also possible to specify the type or the default value of a parameter.

       1  routine MyRout( name : string, index = 0 )
       2  {
       3     io.writeln( "NAME  = ", name )
       4     io.writeln( "INDEX = ", index )
       5  }

    Here name is specified as string, and index is specified as an integer with default
    value 0. Any parameter after a parameter with default value must have default values as
    well. If a routine is called with wrong type of parameters, or no value is passed to a
    parameter without a default value, an exception will be raised and the execution will
    abort.

     0.3  Routine Overloading

    Routine overloading by parameter types is also supported in Dao, which means that
    multiple routines can be defined with the same name, but different parameter signatures.

       1  routine MyRout( index : int, name = "ABC" )
       2  {
       3     io.writeln( "INDEX = ", index )
       4     io.writeln( "NAME  = ", name )
       5  }
       6
       7  MyRout( "DAO", 123 ) # invoke the first MyRout()
       8  MyRout( 456, "script" ) # invoke the second MyRout()

    For coroutines, please see module.core.coroutine.

    [STRUCTURE]

    dao.routine--| dao.routine: Routine (12.6 KB)
                 |--anonymous--| dao.routine.anonymous: Anonymous Routine (1.0 KB)
                 |--section----| dao.routine.section: Code Section Methods (3.2 KB)
                 |--decorator--| dao.routine.decorator: Function Decorator (6.4 KB)