set (source destination --)
Inputs
source: Source object assigned todestination.destination: Already-selected destination object or Ref to the destination.
Outputs
- None.
set replaces an already-selected mutable same-schema destination after dereferencing both inputs. No selection happens inside the builtin.
set is the final replacement step after a separate selection form such as @NAME, .@NAME, @, or fieldRead. After dereferencing, source mutability decides whether the source is copied or moved. A Ref source differs from a direct value only by that source mutability.
set replaces the selected destination object itself. If destination is a Ref, the object reached through that Ref is replaced; the stored Ref object is not changed. Replacing a stored Ref object instead requires a combined selection-and-write form such as ! or fieldWrite.
Behavior
- An immutable object and a mutable same-schema destination produce a copy. The original value keeps its contents.
- A mutable object and a mutable same-schema destination produce a move. The original mutable object no longer keeps its previous contents.
- An immutable destination is invalid.
- Different dereferenced schemas are invalid.
- Text destinations are invalid.
- Code destinations are invalid.
Example
"Owner" use
"String" use
{} () {} [
copySource: 7;
copyTarget: 0;
copySource @copyTarget set
("-- immutable value path copies -- " copySource " " copyTarget "\n") printList
moveSource: 5 owner;
moveTarget: 0 owner;
@moveSource @moveTarget set
("-- mutable value path moves -- " moveSource.valid? " " moveTarget.valid? "\n") printList
] "main" exportFunction
Expected Output
-- immutable value path copies -- 7 7
-- mutable value path moves -- FALSE TRUE
See also
@NAMEnode@NAMENamed local or visible-field read that can supply a selected destination forset..@NAMEnode.@NAMENamed field read on a poppedDictthat can supply a selected destination forset.@builtin(ordinal structValue -- selectedItem)Ordinal-based data-input selection and read with the ordinal before the Struct object.fieldReadbuiltin(structValue ordinal -- selectedItem)Ordinal-based data-input selection and read with the Struct object before the ordinal.!NAMEnode!NAMEDirect named write when selection and replacement are combined in one source form..!NAMEnode.!NAMEDirect named field write on a popped mutableDictwhen selection and replacement are combined.!builtin(source ordinal structTarget --)Ordinal-based data-input selection and write with the ordinal before the Struct target.fieldWritebuiltin(source structTarget ordinal --)Ordinal-based data-input selection and write with the Struct target before the ordinal.