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.

vocatio

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

Function, method, chained, and spread spread call expressions.

Syntax: <name>(<args>) | <expr>.<method>(<args>) | <name>(spread <list>)

Category#

function

Examples#

radix/corpus/reference/concept/vocatio/vocatio.fab (canonical · concept)#

Function, method, chained, and spread spread call expressions.

# =============================================================================
# vocatio — Function, method, chained, and spread spread call expressions.
# =============================================================================
#
# What this teaches:
#   • Call expressions — function calls, method calls, and chained fluent interface calls
#   • Spread arguments — `spread <list>` expands a list into positional call arguments
#
# Common mistakes:
#   • confusing vocatio (function-call expression) with fn declaration syntax — vocatio is the call site, not the definition
#
# See also: fn, spread, class
# =============================================================================

# vocatio — function and method call expressions
#
# <name>()                    -- zero-arg call
# <name>(<args>)              -- positional arguments
# <expr>.<method>(<args>)      -- method call on receiver
# <expr>.<m1>().<m2>()         -- chained calls (fluent interface)
# <name>(spread <list>)      -- spread arguments into call
#
# GRAMMAR:
#   callExpr :← expr '(' (expr | spread expr)* ')'
#
# EXPECTED OUTPUT:
#   Salve, arithmetic results, chained builder output, spread-arg sum.

fn saluta() → void {
    print "Salve!"
}

fn adde(int a, int b) → int {
    return a + b
}

fn multiplica(int x, int y) → int {
    return x * y
}

class Computator {
    mut int valor = 0

    fn pone(int n) → Computator {
        self.valor ← n
        return self
    }

    fn duplica() → Computator {
        self.valor ← self.valor * 2
        return self
    }

    fn accipe() → int {
        return self.valor
    }
}

main {
    # Simple call (no arguments)
    saluta()

    # Call with arguments
    let int sum ← adde(10, 20)
    # 30
    print sum

    # Multiple arguments
    let int productum ← multiplica(5, 6)
    # 30
    print productum

    # Method call on object
    mut Computator computator ← Computator {}
    computator.pone(10)
    # 10
    print computator.accipe()

    # Chained method calls
    mut Computator alter ← Computator {}
    let int value ← alter.pone(5).duplica().duplica().accipe()
    # 20
    print value

    # Call with spread
    let list<int> numeri ← [3, 7]
    let int sparse ← adde(spread numeri)
    # 10
    print sparse
}

Expected output:

Salve!
30
30
10
20
10

radix/corpus/reference/reject/vocatio/callee-not-callable-reject.fab (supporting · reject)#

Calling an integer binding is refused because it is not callable.

# =============================================================================
# vocatio — calling a non-callable value is refused
#
# What this teaches:
#   • A call target must be a function, closure, or callable value
#
# Common mistake:
#   • calling an integer binding as if its name were a function
#
# See also: vocatio, call_expr
# =============================================================================
# This exemplum intentionally fails to compile.

main {
    let int x ← 1
    print x(2)
}

Expected: compilation rejects this example.