渲染zh-Hant

unarius

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

Unary negation, logical not, sign comparisons, and optional presence tests.

Syntax: -<expr> | 非 <expr> | <expr> > 0 | <expr> 是 無

Category#

operators

Examples#

radix/corpus/unarius/unarius.fab (canonical · operator-group)#

Unary negation, logical not, sign comparisons, and optional presence tests.

# =============================================================================
# unarius — Unary negation, logical not, sign comparisons, and optional presence tests.
# =============================================================================
#
# What this teaches:
#   • Unary operators — negation (`-`), logical not (`非`), and sign comparisons
#   • Null checks — `est 無` and `非 est 無` for optional presence testing
#
# Common mistakes:
#   • confusing 非 (logical not, prefix) with - (numeric negation) or ¬ (the Unicode not sign)
#
# See also: 非, est, 非 est
# =============================================================================




# unarius — negation, logical not, sign comparisons, and optional presence
#
# -<expr>  非 <布林>  <expr> > 0  <expr> < 0
# <expr> est 無   <expr> 非 est 無
#
# GRAMMAR:
#   unaryExpr :← ('-' | '非') expr
#
# EXPECTED OUTPUT:
#   unarius.expected — unary operator samples.

main {
    # Numeric negation
    const int x ← 5
    const int neg ← -x
    # -5
    print neg

    # Logical negation
    const bool flag ← true
    const bool non_signum ← not flag
    # 假
    print non_signum

    # Positive/negative checks
    const int a ← 10
    const int b ← -3
    # 真
    print a ≻ 0
    # 假
    print a ≺ 0
    # 假
    print b ≻ 0
    # 真
    print b ≺ 0

    # Null checks
    const string ∪ none forsitan ← null
    # 真
    print forsitan is none
    # 假
    print forsitan not is none
    const string ∪ none adest ← "salve"
    # 假
    print adest is none
    # 真
    print adest not is none
}

Expected output:

-5
falsum
verum
falsum
falsum
verum
verum
falsum
falsum
verum