PreviousNext
Help > EXTREME PROGRAMMING WITH RITTLE > Morphing Functions
Morphing Functions

Morphing functions exhibit different behaviour depending on some input condition.

Within a function a few different blocks of declarations with “input”, “output”, and “refer” type variables, can exist, and the execution to branch to a particular part in the function, and that based on an external condition.

In an example:

 

func foo;

    var input small form;                  ‘ this value defines the behaviour

 

    if form==0;

        var input small a, b, c;            ‘ the function takes three byte values

        var output real z;                     ‘ and returns one real

       ………………………………………

       ………………………………………

 

    else form==1;

        var input text s1, s2;               ‘ the function takes two texts

        var output real t1, t2;             ‘ and returns two texts

       ………………………………………

       ………………………………………

 

    else;

        var input int x, y;                      ‘ the function takes two integers

        var refer real p [10];                ‘ and refers to array

       ………………………………………

       ………………………………………

 

    endif;

endfunc;