Prototypes

GoMelan supports prototypes, like in C, when you have to use a function that is declare under the use calling function, you have to declare it above. If you do not, the script will not compile.

fn power(x: Int, y: Int) -> Int;

fn main() -> Int
{
    total: Float = 3.4;
    a: [Int] = [1, 3, -4, 2, 0, 6, -6];

    return power(floatToInt(total) + sum(a), 3);
}

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

Output:

2197
  1. Declare the main function.

  2. Declare the power function.

  3. Paste the prototype above the main function.

Last updated