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
Declare the main function.
Declare the power function.
Paste the prototype above the main function.
Last updated
Was this helpful?