newVarOfTheSameType (schema -- newValue)
Inputs
schema: Object orRefwhose dereferenced schema is copied for the new object.
Outputs
newValue: Fresh object created only from the dereferenced schema, without using current contents.
newVarOfTheSameType is a fresh-object creation builtin that uses only the dereferenced schema of its input.
The input may be an object or Ref object, but current contents, current access path, and NIL status are ignored. Only the dereferenced schema participates. Unlike new, current Ref contents, current access path, and NIL status never participate here. Applying const or unconst to a Ref input therefore does not change this builtin’s behavior.
Behavior
- In-place schemas produce a fresh object of the same schema with unknown contents.
- Meta schemas produce a new Meta object of the same schema.
- A known
NILRef input is valid whenever its dereferenced schema is valid fornewVarOfTheSameType. - Code schemas are invalid.
- Text schemas are invalid.
Example
{} 0 {} [
template: 7;
"-- current contents are ignored --" printCompilerMessage
template newVarOfTheSameType printStack _:;
template newVarOfTheSameType known? printStack _:;
"-- access path is ignored --" printCompilerMessage
@template newVarOfTheSameType printStack _:;
@template newVarOfTheSameType known? printStack _:;
"-- known NIL Ref still uses schema --" printCompilerMessage
0nx template addressToReference newVarOfTheSameType printStack _:; # a NIL Ref
0nx template addressToReference newVarOfTheSameType known? printStack _:;
"-- meta schema --" printCompilerMessage
() newVarOfTheSameType printStack _:;
() newVarOfTheSameType known? printStack _:;
0
] "main" exportFunction
Expected Output During Compilation
-- current contents are ignored --
Int32
FALSE
-- access path is ignored --
Int32
FALSE
-- known NIL Ref still uses schema --
Int32
FALSE
-- meta schema --
()
TRUE
See also
newbuiltin(object -- newValue)Creates a fresh object from a Ref object, Block object, or Meta object; unlikenewVarOfTheSameType, Ref contents andNILstatus participate, so immutable Ref views copy, mutable Ref views move, and knownNILRef objects are invalid.setbuiltin(source destination --)Replaces an already-selected mutable same-schema destination.