! (source ordinal structTarget --)
Inputs
source: Object written to the selected item.ordinal: Zero-based item ordinal to write.structTarget: Struct object or Ref to Struct receiving the write.
Outputs
- None.
Writes one selected item by zero-based item ordinal, with the source and ordinal before the Struct target.
structTarget is dereferenced for the selection; source keeps its form. For In-place selected items a Ref source is rejected, so a referenced object must be supplied as an object, for example with new. For Ref selected items, replacement still follows the selected item's own Ref schema.
Behavior
- The destination Struct must be mutable.
- The
ordinalinput must be a non-NILInt32. - A known in-bounds ordinal applies the selected item write rule directly.
- A known out-of-bounds ordinal is invalid.
- An unknown ordinal is valid only on a non-Meta uniform Struct. In that case the write succeeds, and any known enclosing uniform Struct object becomes unknown because the exact modified item is not known at compile time.
- A non-static In-place item takes a direct object of the same schema by move.
- A Ref item replaces its stored Ref object. The selected referent is not rewritten; only the stored Ref object changes. The input object may be either a Ref whose target schema matches the referent schema or a direct object of the referent schema. An immutable Ref input is invalid when the selected item is a mutable Ref.
- A Text item takes a same-schema Text input object by move.
- A Code item accepts either a same-schema Code input object or a Block input object, which is compiled and stored without being called.
- A static item is invalid.
fieldIsRef describes the selected item schema, not the accepted source form after dereferencing. A non-static In-place item can therefore still require a direct same-schema object even though reading the same item yields a Ref result, while a Ref item can accept either a matching Ref or a direct object of its referent schema.
Example
{} 0 {} [
value: 1;
dict: {
ordinaryField: 2;
referenceField: @value;
codeField: {} () {} codeRef;
};
"-- In-place item write rule --" printCompilerMessage
dict 0 fieldIsRef printStack _:;
7 0 @dict !
0 @dict @ new printStack _:;
"-- Ref item write rule --" printCompilerMessage
dict 1 fieldIsRef printStack _:;
5 1 @dict !
1 @dict @ printStack _:;
"-- code item write rule --" printCompilerMessage
dict 2 fieldIsRef printStack _:;
["-- code item compiled --" printCompilerMessage] 2 @dict !
2 @dict @ printStack _:;
list: (1 2) dynamic;
ordinal: 0 dynamic;
"-- uniform struct through unknown ordinal --" printCompilerMessage
9 ordinal @list !
@list new printStack _:;
0
] "main" exportFunction
Expected Output During Compilation
-- In-place item write rule --
FALSE
7
-- Ref item write rule --
TRUE
5 Ref
-- code item write rule --
TRUE
-- code item compiled --
{} () {} codeRef
-- uniform struct through unknown ordinal --
Int32 2 array
See also
!NAMEnode!NAMENamed destination write by source-text name..!NAMEnode.!NAMENamed field write by source-text name on a popped mutable Dict.@builtin(ordinal structValue -- selectedItem)Ordinal-based one-item read with the ordinal before the Struct object.fieldIsRefbuiltin(schema ordinal -- isRefLike)Ref-like test for one selected item schema.fieldIsVirtualbuiltin(schema ordinal -- hasNoStorage)No-storage test for one selected item.fieldReadbuiltin(structValue ordinal -- selectedItem)Ordinal-based one-item read with the Struct object before the ordinal.fieldWritebuiltin(source structTarget ordinal --)Ordinal-based one-item write with the Struct target before the ordinal.setbuiltin(source destination --)Replaces an already-selected mutable same-schema destination.