Subroutines and scripts

XSharper has a concept of a subroutine, that accepts 0 or more arguments and returns a single object value.

 

As seen above, subroutines may be invoked directly from the expressions.

To execute square subroutine from another script, it's possible to use include action:

 

Finally, execute another script as if it was executed from command line:

 

Isolation level

By default, subroutines have read-only access to the variables of the caller and any set or changed variables in the subroutine body are restored.

 
The code above will print:
 

This behaviour can be changed by caller, by changing attribute isolation

With isolation="none", when no variables are restored, the output will be
 

With isolation="high", the subroutine will have a totally clean variable list, w/o access to the caller variables at all: