Seed7 
 FAQ 
 Manual 
 Screenshots 
 Examples 
 Algorithms 
 Download 
 Links 

 Examples 
 echo args 
 declare stmt 
 template 
 operator 
 file in string 
 simple clock 
 count words 
 subtype 
 Examples 
Template declaring a statement
 previous   up   next 

Templates are just normal functions with types as parameters. The following template function declares 'for' statements:

 const proc: FOR_DECLS (in type: aType) is func
   begin

     const proc: for (inout aType: variable) range (in aType: low) to (in aType: high) do
         (in proc: statements) end for is func
       begin
         variable := low;
         if variable <= high then
           statements;
           while variable < high do
             incr(variable);
             statements;
           end while;
         end if;
       end func;

   end func;

 FOR_DECLS(char);
 FOR_DECLS(boolean);

The body of the 'FOR_DECLS' function contains a declaration of the 'for' statement for the type aType. Calling 'FOR_DECLS' with char and boolean as parameter creates corresponding declarations of 'for' statements. The example above is a simplified part of the standard Seed7 library "seed7_05.s7i".


 previous   up   next