Seed7 
 FAQ 
 Manual 
 Screenshots 
 Examples 
 Algorithms 
 Download 
 Links 

 Examples 
 echo args 
 declare stmt 
 template 
 operator 
 file in string 
 simple clock 
 count words 
 subtype 
 Examples 
Declare an operator
 previous   up   next 

The standard Seed7 library "seed7_05.s7i" contains also the following declarations:

 const type: color is new struct
     var integer: red_part   is 0;
     var integer: green_part is 0;
     var integer: blue_part  is 0;
   end struct;

 const func color: (in color: col1) + (in color: col2) is func
   result
     var color: result is color.value;
   begin
     result.red_part   := (col1.red_part   + col2.red_part)   div 2;
     result.green_part := (col1.green_part + col2.green_part) div 2;
     result.blue_part  := (col1.blue_part  + col2.blue_part)  div 2;
   end func;

This declares the type color and the '+' operator to add two colors. The operator symbol could also be something new like 'additiveAdd'. In this case the syntax of 'additiveAdd' would be:

 $ syntax expr: .(). additiveAdd .() is              -> 7;

Memory for color objects is managed automatically without garbage collection. Additionally it is not necessary to call constructors to initialize color objects.


 previous   up   next