Files
Aer/tests/closure_test.aer
T

38 lines
678 B
Plaintext

import 'console';
class Operations {
public callback ops(int $x, int $y, string $op){
switch($op) {
case 'ADD':
return int() using ($x, $y) {
return $x + $y;
};
break;
case 'SUB':
return int() using ($x, $y) {
return $x - $y;
};
break;
default:
return string() {
return 'Operation is not supported by class.';
};
}
}
}
class Program {
public void main() {
callback $fn;
object $op = new Operations();
$fn = $op->ops(6, 7, 'ADD');
Console::Print($fn() + "\n");
$fn = $op->ops(6, 2, 'SUB');
Console::Print($fn() + "\n");
$fn = $op->ops(6, 7, 'MUL');
Console::Print($fn() + "\n");
}
}