SultanC
  1. Home
  2. Examples
  3. Functions

Calling a function through a value

functions/indirect_call.sn
def double(value: i32): i32 {
    return value + value;
}

def apply(callback: fn(i32): i32, value: i32): i32 {
    return callback(value);
}

def main(): i32 {
    let operation: fn(i32): i32 = double;
    return apply(operation, 21);
}

Run it

With the interpreter, without compiling:

./build/sultanc run examples/en/functions/indirect_call.sn

Or compile it to an executable:

./build/sultanc examples/en/functions/indirect_call.sn -o build/example && ./build/example

Source on GitHub   All examples