next up previous contents
Next: Predefined Classes Up: Predefined Features and Classes Previous: Predefined Features and Classes

Predefined Features

  Each class automatically contains several predefined features or features with special properties. These comprise:
  1. string: STRING

    string is a parameterless procedure delivering an object of type STRING representing the current value of an object. In case of simple value types the string is a denotation. Otherwise it has the form of an aggregate tex2html_wrap_inline2555 listing all the attributes which have simple values whereas the values of attributes of a reference type are replaced by a hash sign #. string may be redefined to provide more appropriate representations.

  2. is_equal($OB): BOOL

    This procedure returns true, if the arguments is the same as self. That means identity for reference objects and same value for value objects. If the argument and self are of different type, is_equal returns false.

  3. type : TYPE

    Every class type defines a constant type : TYPE with a value which is different for each class type. For an object a a string representation of its type may be obtained by a.type.str.

  4. copy : SAME

    This procedure delivers a new object of the same type containing copies of the values of all attributes of the current object. The type must be a reference type.

  5. init 

    If defined, the init method is called during object creation, before attributes defined by initialized declarations receive their initial values. Init must not be called explicitely. If an invariant method is supplied, this is not checked right after the call to init, but when all initializations are processed.

  6. finalize

    This procedure is called before an object is destructed. This will happen on return from methods for local value objects or when the garbage collector removes an object.

  7. invariant : BOOL

    If the programmer supplies such a procedure in a class then it is supposed to define the class invariant. If the call returns the result false then the exception INVARIANT_ERROR is raised.

The class OB defines a stream method

stream until(b: BOOL) is loop if b then return; end; resume; end; end;

which may be used to define loops that are executed at least once.

Example: The typical usage of until is

loop ... until!(all_done); end;

The parameter b of until is not declared once. So b is reevaluated for every stream call and not only for the first call. tex2html_wrap_inline1707

The classes INT, SHORT_INT, LONG_INT, UNSIGNED, SHORT_UNSIGNED, LONG_UNSIGNED and INTINF define streams

stream upto(!to:SAME):SAME is res := self; loop if res > to then return; end; resume; res := res + 1; end; end;

stream downto(!to: SAME): SAME is res := self; loop if res < to then return; end; resume; res := res - 1; end; end;

that may be used for for-loops.

Example: Its typical usage is

loop 1.upto!(i); ... end;

The parameter to of upto is declared once. So to is only evauated once for the first call. Later changes of i will not affect the number of iterations. tex2html_wrap_inline1707


next up previous contents
Next: Predefined Classes Up: Predefined Features and Classes Previous: Predefined Features and Classes

Martin Trapp
Mon Feb 17 16:49:16 MET 1997