Renderingen-US

Experimental through version 1. Version 0 was alpha. This is the first language release: the interface is relatively stable, not frozen. Nothing is promised stable until version 2.

⇜

Translation status: English reader-locale proof. Term names and code fences follow the en pack; supporting prose may still be English.

Sink-into writes one exactly typed item with ⇜, the operator form of sink.sink(item).

Syntax: <mut Sink<T>> ⇜ <T>

Category#

tensor

  • ⇇
  • transfer

Examples#

radix/corpus/reference/operator/sink-into/sink-into.fab (canonical · operator)#

Sink-into writes one exactly typed item with ⇜, the operator form of sink.sink(item).

# =============================================================================
# ⇜ — sink-into writes one item to a Sink<T>
# =============================================================================
#
# What this teaches:
#   • `sink ⇜ item` is the statement form of `sink.sink(item)`
#   • The item must be exactly the `T` in `Sink<T>`; the operator does not
#     implicitly convert it
#   • A sink chooses its own meaning for one item and for `flush()`
#
# The local contract below is the same marked Sink<T> contract Norma exports.
# `TextSink` records exact items so both the method and glyph forms are visible.

@ radix contract "sinking"
interface Sink<T> {
    fn sink(T item) → void ⇥ string
    fn flush() → void ⇥ string
}

class TextSink implements Sink<string> {
    mut list<string> items = empty

    fn sink(string item) → void ⇥ string {
        self.items.append(item)
    }

    fn flush() → void ⇥ string {
    }
}

fn write(mut TextSink sink) → void ⇥ string {
    sink.sink("method")
    sink ⇜ "operator"
    sink.flush()
}

main args args {
    if args.length() ≻ 0 {
        assert args[0] ≡ "sink"
    }
    mut TextSink sink ← TextSink { items = [] }
    do {
        write(mut sink)
    }
    catch error {
        print error
    }
    print sink.items
}

Expected output:

["method", "operator"]

radix/corpus/reference/reject/sink-into/sink-into-rule-3-item-type-reject.fab (supporting · reject)#

Rule 3 rejects an item that is not exactly the T of Sink<T>.

# Rule 3: the item must be exactly the type parameter in Sink<T>; ⇜ never
# inserts an implicit conversion.

@ radix contract "sinking"
interface Sink<T> {
    fn sink(T item) → void ⇥ string
    fn flush() → void ⇥ string
}

class TextSink implements Sink<string> {
    mut list<string> items = empty

    fn sink(string item) → void ⇥ string {
        self.items.append(item)
    }

    fn flush() → void ⇥ string {
    }
}

fn write(mut TextSink sink) → void {
    sink ⇜ 7
}

main {}

Expected: compilation rejects this example.

radix/corpus/reference/reject/sink-into/sink-into-rule-5-value-reject.fab (supporting · reject)#

Rule 5 rejects using sink-into as a value because ⇜ is a statement with no result.

# Rule 5: sink-into is a statement, not an expression that yields a value.

@ radix contract "sinking"
interface Sink<T> {
    fn sink(T item) → void ⇥ string
    fn flush() → void ⇥ string
}

class TextSink implements Sink<string> {
    mut list<string> items = empty

    fn sink(string item) → void ⇥ string {
        self.items.append(item)
    }

    fn flush() → void ⇥ string {
    }
}

fn write(mut TextSink sink) → void {
    let string result ← sink ⇜ "item"
}

main {}

Expected: compilation rejects this example.

radix/corpus/reference/reject/sink-into/sink-into-rule-6-let-reject.fab (supporting · reject)#

Rule 6 rejects writing through a Sink<T> reached through a let binding.

# Rule 6: a sink reached through `let` is read-only, just like a mutating
# method receiver reached through that binding.

@ radix contract "sinking"
interface Sink<T> {
    fn sink(T item) → void ⇥ string
    fn flush() → void ⇥ string
}

class TextSink implements Sink<string> {
    mut list<string> items = empty

    fn sink(string item) → void ⇥ string {
        self.items.append(item)
    }

    fn flush() → void ⇥ string {
    }
}

main {
    let TextSink sink ← TextSink { items = [] }
    sink ⇜ "item"
}

Expected: compilation rejects this example.

radix/corpus/reference/reject/sink-into/sink-into-rule-8-non-sink-reject.fab (supporting · reject)#

Rule 8 rejects a left operand that does not implement the marked Sink<T> contract.

# Rule 8: only a value conforming to the marked Sink<T> contract accepts ⇜.
# Tensor writes use ⇇; ordinary values are not implicitly made sinks.

@ radix contract "sinking"
interface Sink<T> {
    fn sink(T item) → void ⇥ string
    fn flush() → void ⇥ string
}

main {
    let int value ← 0
    value ⇜ "item"
}

Expected: compilation rejects this example.