Navigation
Synopsis Evaluate a (list of) Rascal commands and return the value of the last command.
Function
  1. Result[&T] eval(type[&T] typ, str command) throws Timeout, StaticError, ParseError
  2. Result[value] eval(str command)
  3. Result[&T] eval(type[&T] typ, list[str] commands) throws Timeout, StaticError, ParseError
  4. Result[value] eval(list[str] commands)
  5. Result[&T] eval(type[&T] typ, str command, int duration) throws Timeout, StaticError, ParseError
  6. Result[value] eval(str command, int duration)
  7. Result[&T] eval(type[&T] typ, list[str] commands, int duration) throws Timeout, StaticError, ParseError
  8. Result[value] eval(list[str] commands, int duration)
Usage import util::Eval;
Description Evaluate a command or a list of commands and return the value of the last command that is executed.

Note that a command can be one of:
  • Statement
  • Declaration
  • Import
  • Extend
  • SyntaxDefinition
The notable exclusion are Expressions. An Expression is not allowed as a command to the eval function. You can easily make a Statement from an Expression by adding a semi-colon.

An optional duration argument may be present to limit the time (in milliseconds) the execution may take. By default, the duration is set to 1000 ms.
Examples
rascal>import util::Eval;
ok
rascal>eval("2 * 3;");
Result[value]: result(6)
rascal>eval(["X = 2 * 3;", "X + 5;"]);
Result[value]: result(11)
Is this page unclear, or have you spotted an error? Please add a comment below and help us to improve it. For all other questions and remarks, visit ask.rascal-mpl.org.