corx


A statically typed, general-purpose programming language, crafted for simplicity and performance.

"Trust the programmer" - corx








# Declaration and definition

Defines the structure of a struct, including its fields and optional default values.


struct point {
    int x;      # declaration only
    int y = 2;  # declaration with default value
};
        

# Access modifiers and visibility

Specifies visibility levels (external, internal, restrict) for fields in a struct, controlling their accessibility across inheritance. Visibility of type e.g. struct and contract is module level.


internal struct point {  # module level access modifier
    external int x = 1;  # accessible publicly. Type level access modifier
    internal int y = 2;  # accessible within inheritance
    restrict int z = 3;  # accessible only within the struct
};
        

# Inheritance / struct composition

A struct can inherit from one or more structs. In the example below the commented lines shows how a struct changes after inheriting from other struct. Though if a structs field has restrict visibility, it won't be available in the child struct. Every declaration has external or public visibility by default.


struct point {
    int x = 1;
    int y = 2;
};

struct circle : point {
    # int x = 1;
    # int y = 2;
    float radius;
};
        

# Multiple inheritance

Supports inheritance from multiple structs, combining their fields into a single derived struct.


struct point {
    int x = 1;
    int y = 2;
};

struct element {
    int id;
    string name;
    string color = "#a2e981";
};

struct circle : point, element {
    float radius;
};
        

# Contracts implementation

Implements behavior defined in contracts, enabling a struct to provide concrete functionality for declared methods.


contract action {
    void move();   # declaration
};

struct point {
    int x = 1;
    int y = 2;
} action;
        

# Multiple contracts implementation

Allows a struct to implement multiple contracts, combining behaviors and ensuring adherence to multiple interfaces.


contract action {
    void move();
};

contract visual {
    void render();
};

struct point {
    int x = 1;
    int y = 2;
} action, visual;
        

# Composition with contract implementation

Combines inheritance with contract implementation, allowing a struct to inherit fields and implement specific behaviors.


contract action {
    void move();
};

struct point {
    int x = 1;
    int y = 2;
};

struct circle : point {
    float radius;
} action;                # 'circle' implements the 'action' contract
        

# Type definition

Introduces type aliases for structs or their combinations with contracts, enabling semantic clarity and reusability in code.


struct circle {
    float radius;
};

type circle shape;        # 'shape' is a type alias for this struct