Kết xuấtvi

vocatio

Translation status: Tiếng Việt reader-locale proof. Term names and code fences follow the vi pack; supporting prose may still be English.

Function, method, chained, and rải spread call expressions.

Syntax: <name>(<args>) | <expr>.<method>(<args>) | <name>(rải <danh_sách>)

Category#

expression

Examples#

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

Function, method, chained, and rải spread call expressions.

# =============================================================================
# vocatio — Function, method, chained, and rải spread call expressions.
# =============================================================================
#
# What this teaches:
#   • Call expressions — function calls, method calls, and chained fluent interface calls
#   • Spread arguments — `rải <danh_sách>` expands a list into positional call arguments
#
# Common mistakes:
#   • confusing vocatio (function-call expression) with hàm declaration syntax — vocatio is the call site, not the definition
#
# See also: hàm, rải, kiểu
# =============================================================================




# vocatio — function and method call expressions
#
# <tên>()                    -- zero-arg call
# <tên>(<args>)              -- positional arguments
# <expr>.<method>(<args>)      -- method call on receiver
# <expr>.<m1>().<m2>()         -- chained calls (fluent interface)
# <tên>(rải <danh_sách>)      -- spread arguments into call
#
# GRAMMAR:
#   callExpr :← expr '(' (expr | rải 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 {
    var int giá_trị = 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
    const int tổng ← adde(10, 20)
    # 30
    print tổng

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

    # Method call on đối_tượng
    var Computator computator ← Computator {}
    computator.pone(10)
    # 10
    print computator.accipe()

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

    # Call with rải
    const list<int> numeri ← [3, 7]
    const int thưa ← adde(spread numeri)
    # 10
    print thưa
}

Expected output:

Salve!
30
30
10
20
10