渲染zh-Hans

scalaria

Translation status: 简体中文 reader-locale proof. Term names and code fences follow the zh-Hans pack; supporting prose may still be English.

Scalar operations on 整数, 小数, and 布尔 in function signatures.

Syntax: 函数 <name>(<scalar-params>) → <scalar-type> <block>

Category#

type

Examples#

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

Scalar operations on 整数, 小数, and 布尔 in function signatures.

# =============================================================================
# scalaria — Scalar operations on 整数, 小数, and 布尔 in function
# signatures.
# =============================================================================
#
# What this teaches:
#   • Primitive type operations — demonstrates `整数` arithmetic, `小数`
#     division, `布尔` comparison and boolean logic in function signatures
#   • Function composition — shows how scalar types compose through parameters
#     and return types
#
# Common mistakes:
#   • Mixing `整数` and `小数` without explicit `↦` 变换 — primitive families have distinct type widths (SEM008).
#
# See also: 整数, 小数, 布尔
# =============================================================================



# scalaria — scalar operations on primitive types
#
# Demonstrates 整数, 小数, and 布尔 parameters with arithmetic,
# comparison, and boolean logic in function signatures.
#
# GRAMMAR:
#   funcDecl :← '函数' ident '(' paramList ')' ('→' type)? block
#
# EXPECTED OUTPUT:
#   Compile-only declaration tour (no 入口).

fn numerica(int a, int b) → int {
    return (a + b) * 2
}

fn fracta(float a, float b) → float {
    return (a + b) / 2.0
}

fn comparata(int a, int b) → bool {
    return a ≤ b
}

fn logica(bool a, bool b) → bool {
    return not a and b
}