new (object -- newValue)

Inputs

Outputs

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

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