Kết xuấtvi

trả

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 returning a string literal via trả \"văn_bản\".

Aliases: return

Syntax: trả <string-literal>

Category#

transfer

Examples#

radix/corpus/redde/redde.fab (canonical · keyword)#

Returns a value from a function.

# =============================================================================
# trả — Returns a value from a function.
# =============================================================================
#
# What this teaches:
#   • Function return — `trả <expression>` returns a value from a `hàm`,
#     and bare `trả` returns `trống`
#   • Early returns with `nếu <cond> do_đó trả <expr>` for guard clauses
#
# Common mistakes:
#   • Using `trả` outside a function body — `trả` is only valid inside `hàm` declarations (SEM032).
#
# See also: →, ⇥, do_đó, ném, im_lặng
# =============================================================================

# trả statements (function return)
#
# trả <expression>   -- return a value
# trả                -- return void (trống)
#
# GRAMMAR:
#   returnStmt :← 'trả' expr?
#
# EXPECTED OUTPUT:
#   30, Salve, Munde, 42, 0, 20

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

fn saluta(string tên) → string {
    return "Salve, " + tên
}

fn duoetquadraginta() → int {
    return 42
}

fn tace() → void {
    # bare trả for trống return type
    return
}

fn porta(int x) → int {
    if x ≺ 0 {
        # early return on negative input
        return 0
    }
    return x * 2
}

main {
    print adde(10, 20)
    print saluta("Munde")
    print duoetquadraginta()
    tace()
    print porta(-5)
    print porta(10)
}

Expected output:

30
Salve, Munde
42
0
20

radix/corpus/scalar/return-bool.fab (canonical · keyword)#

Functions returning boolean literals via trả đúng and trả sai.

# =============================================================================
# trả — Functions returning boolean literals via trả đúng and trả sai.
# =============================================================================
#
# What this teaches:
#   • Boolean return values — `trả đúng` and `trả sai` are valid return
#     expressions for `logic`-typed functions
#   • Demonstrates that boolean literals pass through the return statement
#     unchanged
#
# Common mistakes:
#   • Confusing a scalar (single-value) return with a collection return — this function returns one `logic`, not a list.
#
# See also: đúng, sai, logic, hàm
# =============================================================================

# scalar/return-bool — return boolean literals
#
# GRAMMAR:
#   returnStmt :← 'trả' expr
#
# Verifies that the Swift backend emits functions returning
# boolean literals (SC-001: primitives, functions, return).

fn da_verum() → bool {
    return true
}

fn da_falsum() → bool {
    return false
}

radix/corpus/scalar/return-integer.fab (canonical · keyword)#

Function returning an integer literal via trả 42.

# =============================================================================
# trả — Function returning an integer literal via trả 42.
# =============================================================================
#
# What this teaches:
#   • Integer return values — `trả 42` returns an integer literal from a
#     `số`-typed function
#   • Verifies the backend emits the correct primitive type for integer returns
#
# Common mistakes:
#   • Confusing a scalar (single-value) return with a collection return — this function returns one `số`, not a list.
#
# See also: trống, hàm
# =============================================================================

# scalar/return-integer — return integer literal
#
# GRAMMAR:
#   returnStmt :← 'trả' expr
#
# Verifies that the Swift backend emits a function returning an
# integer literal (SC-001: primitives, functions, return).

fn da_numerum() → int {
    return 42
}

radix/corpus/scalar/return-string.fab (canonical · keyword)#

Function returning a string literal via trả \"văn_bản\".

# =============================================================================
# trả — Function returning a string literal via trả "văn_bản".
# =============================================================================
#
# What this teaches:
#   • String return values — `trả "văn_bản"` returns a string literal from a
#     `văn_bản`-typed function
#   • Verifies the backend handles string literal return types correctly
#
# Common mistakes:
#   • Confusing a scalar (single-value) return with a collection return — this function returns one `văn_bản`, not a list.
#
# See also: văn_bản, hàm
# =============================================================================

# scalar/return-string — return string literal
#
# GRAMMAR:
#   returnStmt :← 'trả' expr
#
# Verifies that the Swift backend emits a function returning a
# string literal (SC-001: primitives, functions, return).

fn da_textum() → string {
    return "textus"
}