渲染zh-Hans

空

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

Represents the null value and can prefix a null check.

Syntax: 空类型 [<expression>]

Category#

literal

Examples#

radix/corpus/literalia/nihil.fab (canonical · keyword)#

Null literal and nullable union bindings.

# =============================================================================
# 空类型 — Null literal and nullable union bindings.
# =============================================================================
#
# What this teaches:
#   • the `空类型` literal — represents absence of a value (null)
#   • nullable union types with `∪` — `T ∪ 空类型` for values that may be absent
#   • null checks with `est 空类型` and `非 est 空类型`
#
# Common mistakes:
#   • Using 空类型 without declaring the type as T ∪ 空类型 — 空类型 requires a nullable union type.
#
# See also: ∪, 可选, 空类型
# =============================================================================

# literalia/nihil — 空类型 literal and T ∪ 空类型
#
# GRAMMAR:
#   literal :← '空类型'
#   unionType :← type '∪' '空类型'
#
# EXPECTED OUTPUT:
#   空类型, 真, 42
#
# BACKEND:
#   Cross-ref 空类型/nihil.fab.

fn maybe() → int ∪ none {
    return 42
}

main {
    const int ∪ none absent ← null
    print absent
    const bool nihilne ← absent is none
    print nihilne
    print maybe() not is none
}

Expected output:

nihil
verum
verum

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

Represents the null value and can prefix a null check.

# =============================================================================
# 空类型 — Represents the null value and can prefix a null check.
# =============================================================================
#
# What this teaches:
#   • the `空类型` keyword — used for null/none values
#
# Common mistakes:
#   • Using 空类型 without ∪ in the type position — nullable types must be declared as T ∪ 空类型.
#
# See also: ∪, 可选
# =============================================================================

# 空类型 — null literal
#
# GRAMMAR:
#   literal :← '空类型'
#
# EXPECTED OUTPUT:
#   Scalar stdout smoke (see body).
#

main {
    const none nothing ← null
    print nothing
}

Expected output:

nihil