Seed7 - The extensible programming language
Seed7 FAQ Manual Screenshots Examples Libraries Algorithms Download Links
Examples echo args file in string simple clock count words subtype map function generic func declare stmt template operator 3-way if
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 library "forloop.s7i".


 previous   up   next