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);
}عرف ضاعف(القيمة: ص32): ص32 {
أرجع القيمة + القيمة;
}
عرف طبق(العملية: دالة(ص32): ص32, القيمة: ص32): ص32 {
أرجع العملية(القيمة);
}
عرف الرئيسية(): ص32 {
دع العملية: دالة(ص32): ص32 = ضاعف;
أرجع طبق(العملية, 21);
}
Run it
With the interpreter, without compiling:
./build/sultanc run examples/en/functions/indirect_call.snOr compile it to an executable:
./build/sultanc examples/en/functions/indirect_call.sn -o build/example && ./build/example