Wilang Documentation1.0.0+4

Variables, globals and REPL#

Local variables and dependencies#

An assignment is available to later cells in the same note. Each note and the REPL has its own local scope, so assigning a in a note does not assign it in another note or in the REPL. Redefining a name changes what later cells read, so move definitions above their uses.

Example
a = 2
a * 3

The inspector separates System names, Globals, and local values. A stale indicator means a result depends on input or settings that changed. Evaluate it, or use Re-evaluate All Cells. An error in a definition can leave dependent cells unable to calculate, so fix the first failing definition first.

The previous answer (ans)#

ans is always lowercase, never translated, and needs no declaration. Each cell's incoming answer is the previous cell's result in document order — never a later cell, and never the previous pass's final value:

2 + 3       -> 5
ans * 2     -> 10
ans + 100   -> 110
z = 5       -> 5        (the answer stays 110)
ans + 1     -> 111

Only a single computational expression publishes implicitly. Assignments (a = 5, (a = 5)), function definitions, and multi-statement blocks (a = 1; b = 2, or a single suppressed 5;) stay transparent: they keep their ordinary definitions and never publish. An explicit ans = 7 is an ordinary assignment and becomes the answer until another eligible expression replaces it — including inside a block, where the block's trailing value must not overwrite it (ans = 7; a = 2 leaves the answer at 7).

A cell that fails publishes nothing: cells that read the answer are blocked instead of consuming the old value, and the previous visible results stay on screen. An unrelated failure (for example a broken assignment to another name) does not disturb the answer, and a later independent expression — or ans = 0 — starts a fresh branch. Values that cannot be restored exactly (units, matrices, and other untyped results) still publish in the cell that produced them, but they are recomputed by replay rather than restored from a snapshot.

Before any producer succeeds, ans is a recognized name with an unavailable value: reading it reports an undefined name instead of inventing 0, and completion offers it as a keyword from an empty document on. Each note and the REPL keep their own answer, and clearing the REPL resets it. Do not create a global variable named ans: the name is reserved, validation rejects it, and pre-existing ones are never injected.

Global variables and functions#

Open Go → Global Variables, or choose Global Variables in the command palette. Create a variable by entering its name and expression. Create a function by entering its name, parameters, and body. Edit or delete definitions from that same screen.

Global definitions are stored locally and supplied to note and REPL sessions. They are evaluated when their definitions change, not on every keystroke, so do not use a global as a continuously refreshing clock or random generator. Editing a global can force recalculation of every note that uses it.

Use names that do not collide with built-ins. Allow override in Math settings controls whether protected names can be shadowed, and an override can make a familiar function name mean something else. If a function unexpectedly stops working, check the inspector and remove the local or global definition.

Custom units#

In Global Variables, choose a new Unit definition. Enter a unit name, a definition such as 2 m, optional aliases, an accepted prefix family, and an offset when the unit needs one. Validation rejects invalid names, invalid definitions, and conflicting entries. Save the definition, then use it in math cells. Edit or delete it from the same screen.

Persistent custom units are shared app-wide, not local variables. Deleting or changing one can break saved expressions that use it, and exporting a single note is not a backup of your app-wide definitions. Keep a separate record of your names and definitions when you move machines.

Direct createUnit calls are an advanced runtime-wide alternative. Run their recipe in a full note. Their registrations are not persistent management entries, so do not assume closing that note removes them. See the createUnit reference.

REPL scratch calculations#

Open REPL. Enter an expression and submit it, then enter another that uses a variable you assigned earlier. Locals persist across submissions, which makes the REPL useful when you do not need a saved notebook structure. Multiline input can contain several statements, and results appear in the submission history.

Use the history controls to revisit, search, copy, and reuse earlier expressions. A recalled expression does not become current state until you evaluate it.

Completion and function signatures use the same language as note cells. Plot directives are note metadata, not REPL commands.

History and clearing#

Enter history() to query history, and history("query") to filter it. The history UI lets you select an earlier expression directly.

Destructive action. Enter clear() to reset the REPL calculation session. This also permanently clears stored REPL history, so copy anything you want to keep first.

history and clear belong to the REPL. They do not work in note cells or in documentation example cells. REPL math settings can override display and calculation defaults without changing a note's local values.

Next steps: All constants · All functions · Workspace and notes