new

new (value -- newValue)

Inputs

Outputs

new is a fresh-value creation builtin. It creates a fresh value from a Ref, Block, or Meta current stack value.

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 an In-place local or field, NAME or .NAME uses the immutable Ref case, while @NAME or .@NAME uses the mutable Ref case.

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

Module-loading wrapper lines are omitted below.

Expected Output During Compilation

-- unknown contents through immutable Ref --
Int32
-- meta value --
()

Expected Output

-- immutable local -- 7 7
-- mutable local -- TRUE FALSE

See also