Introduction to logic parts

Logic parts define a sequence of instructions. Most logic parts contain one or more functions, which are the basic unit of logic.

A function can receive parameters, execute EGL statements, and return a value to the function that called it. Following is a simple example of a function:
Function addIntegers(int1 int in, int2 int in) returns (int)
    sum int = int1 + int2;
    return (sum);
end
For more details, see Functions.

A function is not technically a logic part, although it is possible for a function to exist outside of a logic part and thus behave like a logic part. See Stand-alone function part.

Program
A program is the simplest kind of logic part. A program in EGL behaves similarly to programs in many other programming languages. An EGL program must contain a function named main, which is the function that is invoked when the program runs. The program can contain any number of other functions. The following example shows a simple program part:
package programs;

program multiplicationTable type BasicProgram
    
    stopNumber int = 7;
    
    function main()
        SysLib.writeStderr("Printing multiplication table through " 
            :: stopNumber);
        i, j int;
        
        for (i from 1 to stopNumber by 1)
            for (j from 1 to stopNumber by 1)
                printProduct(i, j);
            end
        end
        
        SysLib.writeStderr("Finished.");
    end
    
    function printProduct(int1 int in, int2 int in)
        SysLib.writeStderr(int1 :: "x" :: int2 :: 
            "=" :: int1*int2);
    end
    
end
Library
A library part is a collection of functions and variables that are made available locally to other logic parts. Functions in a library part can be invoked in any order, while the main function in a program always runs first. The following example shows a simple library part:
package libraries;

library myMathLibrary type BasicLibrary
    
    function addIntegers(int1 int in, int2 int in) 
        returns (int)
        return (int1+int2);
    end
    
    function subtractIntegers(int1 int in, int2 int in) 
        returns (int)
        return (int1-int2);
    end
    
end
Handler
A Handler part is specialized to control a particular kind of user interface.
BasicHandler
BasicHandler parts are the simplest kind of Handler. Generally, you will use a Handler that is specialized for a type of interface.
JSFHandler
JSF Handler parts control web pages. See Elements of a JSF web application.
JasperReport
Jasper Report Handler parts control reports that are created by EGL within the Jasper Reports framework. See Elements of an EGL JasperReport application.
Service
Like a library part, a service part is a collection of functions, but unlike a library part, the service part is designed to enable applications outside the current run unit to use the functions.
Interface
An interface part is different from most logic parts because instead of containing functions or any executable code, it contains function prototypes. Instead of defining actual logic, as the other types of logic part do, an interface part merely describes another logic part, usually a service part. In EGL, you can use interfaces to plan services or to represent services that your application will use.
ExternalType
With an ExternalType part, you can create variables in EGL that refer to elements in another language. Generally, ExternalType parts are used to represent Java™ objects. An ExternalType part contains function prototypes that allow you to invoke the logic in the Java object. Also, an ExternalType part can contain variables that represent public variables in the Java object. See Calling Java for an example.

Feedback