def (value name --)value: Value bound to the created name.name: Known local or field name.def creates one local or field from a stack value and a known Text name.
The name is taken directly from name as known Text and does not consume the name stack.
Pending specifiers from overload, private, and virtual apply to the created local and are then cleared.
name must be known Text.value.NAME: ...;.value must be packable and known at compile time.{...}, a non-empty name creates a named field and an empty name creates an unnamed item.{} 0 {} [
pendingLabel:
7 "x" def
8;
virtual 4 "staticValue" def
5 "ordinaryValue" def
1 "latest" def
2 "latest" def
"-- def uses its own text name --" printCompilerMessage
x printStack _:;
"-- pending label still used by ; --" printCompilerMessage
pendingLabel printStack _:;
"-- static local --" printCompilerMessage
staticValue printStack _:;
"-- In-place local after static def --" printCompilerMessage
ordinaryValue printStack _:;
"-- latest local wins --" printCompilerMessage
latest printStack _:;
"-- named fields created by def --" printCompilerMessage
{ 100 "score" def 2 "level" def } printStack _:;
"-- duplicate field names created by def --" printCompilerMessage
{ 1 "x" def 2 "x" def } printStack _:;
"-- unnamed items created by def --" printCompilerMessage
{ 1 "" def FALSE "" def } printStack _:;
0
] "main" exportFunction
-- def uses its own text name --
7 Cref
-- pending label still used by ; --
8 Cref
-- static local --
4
-- In-place local after static def --
5 Cref
-- latest local wins --
2 Cref
-- named fields created by def --
{
score: 100;
level: 2;
}
-- duplicate field names created by def --
{
x: 1;
x: 2;
}
-- unnamed items created by def --
(1 FALSE)
NAME: ...; node — Pushes a name onto the name stack and creates a local by consuming that name and one data-stack value.overload builtin (--) Marks the next local created by NAME: ...; or def as participating in overload resolution.private builtin (--) Marks the next local created by NAME: ...; or def as non-public, so use does not import that name from the module.virtual builtin (--) Marks the next local created by NAME: ...; or def as static; virtual is the historical name for this declaration modifier.