def (object name --)
Inputs
object: Object bound to the created name.name: Known local or field name.
Outputs
- None.
def creates one local or field from a stack object 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.
Behavior
namemust be known Text.- A known
NILText name is invalid. - The created local takes its schema and current value from
object. - Pending labels remain unchanged and are consumed only by a later
NAME: ...;. - If the next created local is static,
objectmust be packable and known at compile time. - Inside
{...}, a non-empty name creates a named field and an empty name creates an unnamed item. - Repeating a non-empty name creates another local or field with that name. Normal newest-to-oldest lookup then selects the latest one.
Example
{} 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
Expected Output During Compilation
-- 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)
See also
NAME: ...;node—Pushes a name onto the name stack and creates a local by consuming that name and one data-stack object.overloadbuiltin(--)Marks the next local created byNAME: ...;ordefas participating in overload resolution.privatebuiltin(--)Marks the next local created byNAME: ...;ordefas non-public, sousedoes not import that name from the module.virtualbuiltin(--)Marks the next local created byNAME: ...;ordefas static;virtualis the historical name for this declaration modifier.