virtual (--)
Inputs
- None.
Outputs
- None.
virtual is the declaration modifier that marks the next successfully created local as static.
The name is historical. The resulting field-storage property is what fieldIsVirtual reports. The schema-level Meta test is virtual?.
The builtin sets a pending static specifier in the current scope. That pending specifier is consumed by the next successful local creation through NAME: ...; or def.
Behavior
- If the static specifier is already pending, the builtin raises a duplicate-specifier error.
- After the next successful local creation, the pending static flag is cleared.
- Other operations do not consume the pending static flag.
- A pending static flag is invalid for
exportFunction,importFunction, andimportVariable. - If the scope ends before the pending static flag is consumed, the program is invalid.
- Pending
overloadorprivatespecifiers coexist with the pending static flag. - This does not make the resulting object Meta.
Example
{} 0 {} [
virtual staticLocal: 1;
dict: { virtual 2 "staticField" def };
"-- values created with virtual are static, not meta --" printCompilerMessage
staticLocal printStack _:;
staticLocal virtual? printStack _:;
dict.staticField printStack _:;
dict.staticField virtual? printStack _:;
"-- fieldIsVirtual sees static field storage --" printCompilerMessage
dict 0 fieldIsVirtual printStack _:;
0
] "main" exportFunction
Expected Output During Compilation
-- values created with virtual are static, not meta --
1
FALSE
2
FALSE
-- fieldIsVirtual sees static field storage --
TRUE
See also
NAME: ...;node—Pushes a name onto the name stack and creates a local by consuming that name and one data-stack object.defbuiltin(object name --)Creates a named local or field using a known Text name.exportFunctionbuiltin(inputsSchema output options callable name --)Exports a named function built from a Block and a signature; a pendingvirtualspecifier is invalid there.importFunctionbuiltin(inputsSchema output options name --)Declares or imports a named function with the supplied signature; a pendingvirtualspecifier is invalid there.importVariablebuiltin(schema name --)Creates a local that refers to external variable storage; a pendingvirtualspecifier is invalid there.fieldIsVirtualbuiltin(schema ordinal -- hasNoStorage)No-storage test for one selected item.staticbuiltin(--)Reserved builtin name with no standalone effect.virtual?builtin(schema -- isMeta)Historical Meta-schema test.