virtual

virtual (--)

Inputs

Outputs

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 value-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

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