Expr evaluation runs a script in an evaluation context connected to an Expr session.
The evaluation context is temporary. The session can persist data across evaluations when the host uses the same session name.
Each evaluation has two main phases:
Parse errors stop before any script code runs.
Runtime errors stop during execution.
a = 10; b = 20; a + b;
The final value produced by the script is the evaluation result. In this example, the result is `30`.
A script result is the last produced value unless control flow changes it.
a = 10; a + 5;
The result is `15`.
Assignments also produce values:
a = 10; // produces 10 b = 20; // produces 20
If the last statement is a declaration or another statement that produces no useful value, the result can be `none()`.
function Add(a, b) { return a + b; }
Use an explicit final expression when the caller needs a specific result.
Output functions write to the active output sink. They are separate from the evaluation result.
print('Running'); 42;
This writes `Running` to output and returns `42` as the script result.
Common output functions include:
See Output, Formatting, Clipboard, and Errors.
A session stores state for Expr evaluations.
A session contains:
Named sessions allow state to persist across evaluations that use the same session name.
// first evaluation in session 'job1' count = 1;
// later evaluation in session 'job1' count += 1; count;
The second evaluation can read and update `count` because it uses the same named session.
Different named sessions are isolated from each other.
Host code decides which session name is used for an evaluation.
Common host patterns are:
When a script has no persistent host session, root variables, functions, and classes should not be relied on after the evaluation ends.
The global `session` object can switch the active context to the fallback empty-name session with session.join(''). This is mainly useful for host-controlled or interactive workflows. Prefer named sessions when persistence matters.
The global `session` object exposes session inspection and management.
print(session.current); print(session.list_variables());
Common methods include:
| Method | Description |
|---|---|
| `session.current` | Current session name property. |
| `session.list()` | Lists named sessions. |
| `session.list_variables()` | Lists variables in the current session. |
| `session.list_functions()` | Lists user functions in the current session. |
| `session.list_classes()` | Lists user classes in the current session. |
| `session.create(name)` | Creates a new named session. Does not switch to it. |
| `session.join(name)` | Switches to an existing named session. Empty name joins the fallback session. |
| `session.clear()` | Clears current session variables, user functions, and user classes. |
| `session.has_variable(sessionName, variableName)` | Checks whether another session contains a root variable. |
| `session.get_variable(sessionName, variableName)` | Reads a root variable from another session. Object values are cloned. |
| `session.set_variable(sessionName, variableName, value)` | Sets or removes a root variable in another session. Object values are cloned. |
| `session.delete(name)` | Deletes a named session. Does not switch session; deleting the active or fallback session fails. |
See session.
Built-in global objects are restored when a session is prepared for evaluation.
Current global objects include:
These names are protected. Do not assign over them.
settings = 1; // error controller = 1; // error session = 1; // error python = 1; // error
See Global objects.
Normal top-level assignment creates or updates a root variable in the current session.
feed = 1200;
Root variables are visible to later statements and can be visible to later evaluations when the same named session is reused.
Assigning `none()` removes or clears the variable so that later reads behave as missing.
feed = none(); feed; // none()
User-defined functions and classes are stored in the active session.
function Add(a, b) { return a + b; } class Box(value) { Value = value; }
If the same named session is reused, later evaluations can call the function or construct the class.
Re-defining the same function or class name in a session replaces the previous definition.
During evaluation, Expr uses local scopes for blocks, functions, and methods.
Local variables are created with `set`.
function AddOne(value) { set temp = value + 1; return temp; }
Local variables disappear when their scope ends.
Variable lookup checks local scopes before root/session variables. Inside object methods, object fields also participate in name lookup and assignment rules.
See Variables and assignment and Classes and user-defined objects.
Control-flow statements set internal evaluation state while the current program is running.
These effects do not persist in the session after evaluation ends.
See Control flow.
The evaluation context tracks the source path and profile path used for file resolution.
The profile path is the machine configuration folder. `path()` returns this folder.
The source path is the folder of the current source script used by the host. `path(“”)` returns this folder.
Paths that start with `.` are profile-relative. Paths that do not start with `.` are source-relative.
profile_file = path("./lib/Loader.expr"); source_file = path("job_data.csv");
See How relative paths work and Include system.
Some host objects call Expr callbacks after the original statement has returned.
Examples include:
Callbacks run in a new evaluation context connected to the relevant session when the object invokes them.
Because callbacks can run later, keep callback state in the object instance or in a named session when it must survive beyond the original evaluation.
class Demo() { Count = 0; function OnTimer(count) { Count += 1; } } demo = Demo(); t = timer(demo.OnTimer); t.start(1000, 3);
Object lifetime rules are object-specific. See the relevant object page for details.
Expr session registries and session containers are protected internally.
Each evaluation should use its own evaluation context.
Practical rules:
Thread-safety prevents data-structure corruption. It does not make conflicting script logic automatically correct.
Use a named session for interactive workflows:
count += 1; count;
Use a temporary evaluation for isolated calculations:
set a = 10; set b = 20; a + b;
Use classes for persistent object state inside a session:
class Average() { Count = 0; Total = 0; function Add(value) { Count += 1; Total += value; return Total / Count; } }
Previous: Error model
Next: Host integration