คืน
Translation status: ภาษาไทย reader-locale proof. Term names and code fences follow the th-TH pack; supporting prose may still be English.
Function returning a string literal via คืน \"ข้อความ\".
Aliases: return
Syntax: คืน <string-literal>
Category#
transfer
Related#
Examples#
radix/corpus/redde/redde.fab (canonical · keyword)#
Returns a value from a function.
# =============================================================================
# คืน — Returns a value from a function.
# =============================================================================
#
# What this teaches:
# • Function return — `คืน <expression>` returns a value from a `ฟังก์ชัน`,
# and bare `คืน` returns `เปล่า`
# • Early returns with `ถ้า <cond> ดังนั้น คืน <expr>` for guard clauses
#
# Common mistakes:
# • Using `คืน` outside a function body — `คืน` is only valid inside `ฟังก์ชัน` declarations (SEM032).
#
# See also: →, ⇥, ดังนั้น, โยน, เงียบ
# =============================================================================
# คืน statements (function return)
#
# คืน <expression> -- return a value
# คืน -- return void (เปล่า)
#
# GRAMMAR:
# returnStmt :← 'คืน' expr?
#
# EXPECTED OUTPUT:
# 30, Salve, Munde, 42, 0, 20
fn adde(int a, int b) → int {
return a + b
}
fn saluta(string ชื่อ) → string {
return "Salve, " + ชื่อ
}
fn duoetquadraginta() → int {
return 42
}
fn tace() → void {
# bare คืน for เปล่า 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 คืน จริง and คืน เท็จ.
# =============================================================================
# คืน — Functions returning boolean literals via คืน จริง and คืน เท็จ.
# =============================================================================
#
# What this teaches:
# • Boolean return values — `คืน จริง` and `คืน เท็จ` are valid return
# expressions for `ตรรกะ`-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 `ตรรกะ`, not a list.
#
# See also: จริง, เท็จ, ตรรกะ, ฟังก์ชัน
# =============================================================================
# scalar/return-bool — return boolean literals
#
# GRAMMAR:
# returnStmt :← 'คืน' 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 คืน 42.
# =============================================================================
# คืน — Function returning an integer literal via คืน 42.
# =============================================================================
#
# What this teaches:
# • Integer return values — `คืน 42` returns an integer literal from a
# `จํานวน`-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 `จํานวน`, not a list.
#
# See also: เปล่า, ฟังก์ชัน
# =============================================================================
# scalar/return-integer — return integer literal
#
# GRAMMAR:
# returnStmt :← 'คืน' 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 คืน \"ข้อความ\".
# =============================================================================
# คืน — Function returning a string literal via คืน "ข้อความ".
# =============================================================================
#
# What this teaches:
# • String return values — `คืน "ข้อความ"` returns a string literal from a
# `ข้อความ`-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 `ข้อความ`, not a list.
#
# See also: ข้อความ, ฟังก์ชัน
# =============================================================================
# scalar/return-string — return string literal
#
# GRAMMAR:
# returnStmt :← 'คืน' expr
#
# Verifies that the Swift backend emits a function returning a
# string literal (SC-001: primitives, functions, return).
fn da_textum() → string {
return "textus"
}