Address-based non-owning wrapper that reconstructs one referenced object through one schema-supplier helper. It exists because a schema cannot contain a Ref to itself: write next: [Node] Mref; inside Node where next: Node Ref; would recurse without end; the Block is called only when the wrapper is used.


Construction forms

Mref has effect (getSchema -- mref). In the forms below, getSchema is a Block with effect (-- representative). The first form uses the schema and mutability of the representative returned by getSchema; the second applies Cref to make that representative immutable. An In-place or mutable Ref representative permits a writable result only through a mutable wrapper view.

myRef: @getSchema Mref;        # writable if getSchema returns an In-place or mutable Ref representative
myRef: [getSchema Cref] Mref;  # immutable representative and result

getSchema is one helper that returns one representative object or reference of the required schema.


Stored address model


Lifetime and mutability


Methods

CALL

(-- ref) Reconstructs the current referenced object from the stored address.

Postconditions

  • The result schema is supplied by getSchema and reconstructed through addressToReference.

set

(source --) Stores the address of the supplied target in the wrapper.

Preconditions

  • The dereferenced schemas of source and the supplier's representative must match. For a writable representative, an immutable source Ref is rejected; pass a mutable view such as @value. An In-place source is also accepted. An immutable representative accepts either source view.
  • set is called through a mutable wrapper view, as in @holder.set.
  • The target remains valid for later CALL reconstruction.

Fields


Examples

Mutable and immutable wrappers

"Mref"    use
"control" use

Int32Schema: [0];

{} () {} [
  value: 5;

  holderA: @Int32Schema Mref;
  @value @holderA.set
  holderA printStack _:;

  imholderA: [Int32Schema Cref] Mref;
  @value @imholderA.set
  imholderA printStack _:;
] "main" exportFunction

Expected Output During Compilation

Int32 Ref
Int32 Cref

Runtime example

"Mref"    use
"String"  use
"control" use

Int32Schema: [0];

{} Int32 {} [
  value0: 5;
  value1: 9;
  holder: @Int32Schema Mref;
  @value0 @holder.set
  ("first=" holder new LF) printList
  @value1 @holder.set
  ("second=" holder new LF) printList
  0
] "main" exportFunction

Expected Output

first=5
second=9

See also