new (object -- newValue)
Inputs
object: Object that supplies the new object.
Outputs
newValue: Fresh object created fromobjector from its referenced contents, according to the input kind.
new creates a fresh object from a Ref object, Block object, or Meta object on the current stack.
For a Ref input, current referenced contents participate. new does not use only the dereferenced schema, so a known NIL Ref is invalid even when its dereferenced schema would otherwise be accepted. Unlike newVarOfTheSameType, current Ref contents, current access path, and NIL status all participate here. Applying const or unconst to a Ref input can therefore change whether new attempts to copy or move, and may also change validity.
For a non-static, non-callable In-place local or field, NAME or .NAME supplies an immutable Ref view; @NAME supplies a mutable view, and .@NAME supplies a mutable view only when the enclosing Dict is reached through a mutable path (@dict.@field new moves, dict.@field new copies); see selection.
Behavior
- An immutable Ref view creates a fresh object by copying the current contents.
- A mutable Ref view creates a fresh object by moving the current contents, then reinitializes that referenced storage.
- A Ref object with unknown target contents creates a fresh object with unknown contents.
- A Block object creates a new Block object of the same schema.
- A Meta object creates a new Meta object of the same schema.
- In-place objects are invalid.
Example
"Owner" use
"String" use
{} () {} [
number: 7;
numberCopy: number new;
("-- immutable local -- " numberCopy " " number "\n") printList
ownerValue: 5 owner;
ownerMoved: @ownerValue new;
("-- mutable local -- " ownerMoved.valid? " " ownerValue.valid? "\n") printList
unknownValue: 0 dynamic;
"-- unknown contents through immutable Ref --" printCompilerMessage
unknownValue new printStack _:;
"-- meta value --" printCompilerMessage
() new printStack _:;
] "main" exportFunction
Expected Output During Compilation
-- unknown contents through immutable Ref --
Int32
-- meta value --
()
Expected Output
-- immutable local -- 7 7
-- mutable local -- TRUE FALSE
See also
newVarOfTheSameTypebuiltin(schema -- newValue)Creates a fresh object from only the dereferenced input schema; unlikenew, current contents, value knowledge, andNILstatus do not participate, so a knownNILRef can still be used there.setbuiltin(source destination --)Replaces an already-selected mutable same-schema destination.