[NAME] ALL.dao.routine.anonymous [TITLE] Anonymous Routine [DESCRIPTION] 0.1 Routine As First Class Object Dao also support first class functions / routines. They can be created in the following way: 1 foo = routine( x, y : TYPE, z = DEFAULT ) 2 { 3 codes; 4 } The definition of such functions is identical to the normal function definition, except the following differences: 1. there is no need for a function name, but the created function must be assigned to a variable; 2. the default value expressions for parameters do not necessary to be constant expressions, they are evaluated at running time when the function is created; 3. the function body may contain variables defined in the "upper" function that creates it; depending on the type of the "upper" variable, its copy (for simple types) or reference will be used by the created function. Here is an example, 1 a = "ABC"; 2 3 rout = routine( x, y : string, z = a+a ){ 4 a += "_abc"; 5 io.writeln( "lambda ", a ) 6 io.writeln( "lambda ", y ) 7 io.writeln( "lambda ", z ) 8 } 9 10 rout( 1, "XXX" );