The Freya Programming Language

The entry point

See also

An executable project must have an entry point method, which will be called to initiate execution. This method can be found automatically by the compiler, or you can mark it explicitly.

Rules for the entry point

There are several basic rules for selecting an entry point:

    // Most simple signature for an entry method.
    static method Main;
    // Returns an integer exit code. Zero stands for "normal termination".
    static method Main: Integer;
    // Receives a parsed copy of the command line.
    static method Main(Args: Array[String]);
    // Receives the command line and returns an exit code.
    static method Main(Args: Array[String]): Integer;

This code fragment shows a "Hello, World" application written in Freya:

using System;

namespace Freya.Hello.World;
private

    Program = class
    private static
        method Main(Args: Array[String]);
    end;

implementation for Program is

    method Main(Args: Array[String]);
    begin
        Console.WriteLine('Hello, Freya!');
    end;

end.

We are receiving a copy of the command line, though we're not using it. Please note that Main has been declared static and private. However, you could also declare Main with any access level you prefer.

The special syntax for the entry point

Since, most of the times, the class containing the entry point is declared only with this purpose, a common trick is to declare this class as a static one, like this:

    Program = static class
    private
        method Main(Args: Array[String]);
    end;

Now, all members defined by Program are automatically considered static members of that class.

Actually, there's no need to declare a separate class for only defining a Main method inside. You can use an anonymous implementation section for this purpose. Our previous "Hello, World!" can be written in this shorter form:

using System;

namespace Freya.Hello.World;

implementation

    method Main(Args: Array[String]);
    begin
        Console.WriteLine('Hello, Freya!');
    end;

end.

Anonymous implementations automatically generate a static class containing any members declared inside the implementation section.

See also

The Freya Programming Language
Program and file structure
Lexical structure
Projects and source files
Namespaces
Implementation sections
using clauses
Methods