GLaDOS
  • Home
  • 🌴Introduction
    • Installation
    • Basic Code example
    • Syntax Overview
  • 🤖Developpers
    • Parsing
    • Verbose Mode
  • ✨Features
    • Types
    • Operators
    • Lists
    • Includes
    • Syntactic Sugar
    • Loops
    • Conditions
    • Internal Functions
    • Recursivity
    • Prototypes
    • Error handling
    • Comments
    • Scopes
  • 📚Libraries
    • Mathematics
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
  1. Features

Includes

file maths.gom:

fn abs(x: Int) -> Int
{
    if (x < 0) {
        return (x * -1);
    }
    return x;
}

fn factorial(x: Int) -> Int
{
    if (x < 1) {
        return x * factorial(x - 1);
    }
    return 1;
}

fn sum(a: [Int]) -> Int
{
    s: Int = 0;

    for (i: Int = 0; i < len(a); i++) {
        s += a[i];
    }
    return s;
}

fn power(x: Int, pow:Int) -> Int
{
    if (x == 0) {
        return 0;
    }
    if (y < 0) {
        return (power(x, y + 1) / x);
    }
    return (power(x, y - 1) * x);
}

file main.gom:

include (sum) from "../lib/maths.gom"

fn main() -> Int
{
    a: [Int] = [1, 2, 3, 4];
    return sum(a);
}

Output:

10
  1. Include the sum function from the math lib.

  2. Declare a list of Int.

  3. Call the sum function of the list a and return the result.

PreviousListsNextSyntactic Sugar

Last updated 1 year ago

Was this helpful?

✨