runtime_evaluation_in_an_environment.sf 225 B

1234567891011121314
  1. #!/usr/bin/ruby
  2. #
  3. ## https://rosettacode.org/wiki/Runtime_evaluation/In_an_environment
  4. #
  5. func eval_with_x(code, x, y) {
  6. var f = eval(code);
  7. x = y;
  8. eval(code) - f;
  9. }
  10.  
  11. say eval_with_x('2 ** x', 3, 5); # => 24