Aer Interpreter Source
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
633 B

  1. class Operations {
  2. public callback ops(int $x, int $y, string $op){
  3. switch($op) {
  4. case 'ADD':
  5. return int() using ($x, $y) {
  6. return $x + $y;
  7. };
  8. break;
  9. case 'SUB':
  10. return int() using ($x, $y) {
  11. return $x - $y;
  12. };
  13. break;
  14. default:
  15. return string() {
  16. return 'Operation is not supported by class.';
  17. };
  18. }
  19. }
  20. }
  21. class Program {
  22. public void main() {
  23. callback $fn;
  24. object $op = new Operations();
  25. $fn = $op->ops(6, 7, 'ADD');
  26. print($fn() + "\n");
  27. $fn = $op->ops(6, 2, 'SUB');
  28. print($fn() + "\n");
  29. $fn = $op->ops(6, 7, 'MUL');
  30. print($fn() + "\n");
  31. }
  32. }