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.

call

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

call opens a channel endpoint and materializes the stream with an explicit conversion target.

Syntax: call 'runtime:echo' (payload) ↦ string

Category#

endpoint

Examples#

radix/corpus/reference/annotation/ad/serve-plain.fab (canonical · annotation)#

@ call serves a route from a Faber function; a caller ads the route and materializes the one reply frame.

# =============================================================================
# call — `@ call '<route>'` serves a route from a Faber function.
# =============================================================================
#
# What this teaches:
#   • Serving a route — `@ call 'salutatio:saluta'` registers `saluta` as the
#     program's handler for that route; no host is needed for it
#   • The caller side is unchanged — `call 'salutatio:saluta' ("munde")` opens a
#     channel and `↦ string` materializes the reply
#   • Plain return — a handler that returns one value answers one item frame,
#     then done
#
# Common mistakes:
#   • giving a handler two parameters — a handler takes zero or one opener;
#     pass a class to send several values
#
# See also: call, channel, conversion
# =============================================================================

@ call 'salutatio:saluta'
fn saluta(string name) → string {
    return "salve, " + name
}

main {
    let string responsum ← call 'salutatio:saluta' ("munde") ↦ string
    print responsum
}

Expected output:

salve, munde

radix/corpus/reference/annotation/ad/serve-typed.fab (canonical · annotation)#

A call to a Faber-served route is a typed conversation channel<O, R>: the opener and every reply are checked against the handler.

# =============================================================================
# call — a conversation with a Faber handler is typed `channel<O, R>`.
# =============================================================================
#
# What this teaches:
#   • Typed conversation — when a Faber function serves the route, `call` has
#     type `channel<O, R>`: `O` is the handler's parameter, `R` each item back
#   • Inference — `let _ s ← call '…'` infers `channel<O, R>` from the route
#   • Dropping the types — a typed channel assigns to a bare `channel`, which
#     reads its frames as loose values again
#   • No opener — a handler without a parameter has `O = null`, and the call
#     passes no opener
#
# Common mistakes:
#   • materializing as a type other than `R` or `list<R>` — a compile error
#   • passing an opener of the wrong type — the handler's parameter decides
#   • a bare `channel` is `channel<value, value>`; host routes stay untyped
#
# See also: call, channel, recv, conversion
# =============================================================================

@ call 'numeri:twice'
fn twice(int n) → int {
    return n * 2
}

@ call 'salutatio:greeting'
fn greeting() → string {
    return "salve"
}

main {
    let _ s ← call 'numeri:twice' (21)
    let int doubled ← s ↦ int
    print doubled
    let channel<none, string> g ← call 'salutatio:greeting'
    print g ↦ string
    let channel<int, int> t ← call 'numeri:twice' (5)
    let channel loose ← t
    print loose ↦ int
}

Expected output:

42
salve
10

radix/corpus/reference/keyword/ad/sermo-conversio.fab (canonical · keyword)#

call opens a channel endpoint and materializes the stream with an explicit conversion target.

# =============================================================================
# call — call opens a channel endpoint and materializes the stream with an explicit
# conversion target.
# =============================================================================
#
# What this teaches:
#   • Endpoint materialization — `call 'runtime:echo'(payload) ↦ string` opens a
#     channel connection and converts the stream to a concrete type
#   • The `↦` materialization operator — directs how the inbound frame stream
#     is interpreted
#
# Common mistakes:
#   • confusing call route syntax — the materialization target type must match the endpoint's actual return shape
#
# See also: conversion
# =============================================================================

# Exemplar: expression `call` with `channel ↦ string` materialization.
#
# Proves the conversion returns the echoed opener text as a `string` value.
# The runtime:echo backend echoes the opener back as a single string frame;
# `↦ string` materializes it. The exemplar asserts equality.

main {
    let string t ← call 'runtime:echo' ("salve, munde") ↦ string
    assert t ≡ "salve, munde"
}

radix/corpus/reference/reject/ad/ad-handler-multiple-routes-reject.fab (supporting · reject)#

One handler serves exactly one route; a second @ call annotation on the same function is refused.

# =============================================================================
# call — a handler serves one route, not two
# =============================================================================
# A function annotated with `@ call` is the handler for exactly one route. A
# second `@ call` on the same function has no single route to answer.

@ call 'm:a'
@ call 'm:b'
fn g(int n) → int {
    return n
}

main {
    print 1
}

Expected: compilation rejects this example.

radix/corpus/reference/reject/ad/ad-handler-not-top-level-reject.fab (supporting · reject)#

A call handler must be a top-level function; a @ call annotation on a class method is refused.

# =============================================================================
# call — a handler is a top-level function, never a class method
# =============================================================================
# Registering a route with `@ call` requires a top-level function. A method
# belongs to its class and cannot serve a program route.

class C {
    @ call 'm:a'
    fn g(int n) → int {
        return n
    }
}

main {
    print 1
}

Expected: compilation rejects this example.

radix/corpus/reference/reject/ad/ad-route-duplicate-reject.fab (supporting · reject)#

Two handlers may not serve the same route; a route is served once per program.

# =============================================================================
# call — a route is served once per program
# =============================================================================
# `@ call '<route>'` pins a handler to a route. Two handlers claiming the same
# route would answer the same traffic, so the program is refused.

@ call 'm:x'
fn a() → int {
    return 1
}
@ call 'm:x'
fn b() → int {
    return 2
}
main {
    print 1
}

Expected: compilation rejects this example.

radix/corpus/reference/reject/ad/ad-route-reserved-reject.fab (supporting · reject)#

A served route never lives under the reserved runtime: prefix; runtime routes belong to the host.

@ call 'runtime:echo'
fn a() → int {
    return 1
}
main {
    print 1
}

Expected: compilation rejects this example.