klyn.Application.eval
method
public static native eval(code as String) as Object throws SyntaxError, TypeError, Exception
Description

Compiles and executes a Klyn script provided as a string. The supplied String is executed as-is, without additional reindentation. Triple-quoted literals remove their common margin when the String is created.

Evaluation retains the caller's lexical values, imports and declared types, including types declared by an enclosing eval. Declarations remain local to that evaluation. Thrown exceptions retain their object identity, fields and stack when crossing an eval boundary. In contrast, compile() validates an autonomous fragment with the caller's imports only.

Parameters
ParameterDescription
codeKlyn source code to compile and execute.
Throws
  • SyntaxError if the code contains a syntax error.
  • TypeError if the code contains a type error.
  • Exception if compilation or execution fails.
Example
result = Application.eval("40 + 2")
print(result)