∈
Translation status: 简体中文 reader-locale proof. Term names and code fences follow the zh-Hans pack; supporting prose may still be English.
Checks whether a value is in a list, set, map key set, or enum value set.
Syntax: <expression> ∈ <collection> | <expression> ∉ <collection>
Category#
collection
Related#
- ‥
- …
Examples#
radix/corpus/operatores/membership-collection.fab (canonical · operator-group)#
Checks whether a value appears in a collection.
# =============================================================================
# ∈ — Checks whether a value appears in a collection
# =============================================================================
#
# What this teaches:
# • Checks whether a value appears in a collection.
# • Related operators: ‥, …
#
# Common mistakes:
# • Using `∈` with a non-collection right operand — `∈` checks membership in a 列表, 映射, or 集合 (or a range), and a scalar right operand is rejected (SEM010); for a substring test on text use `contains`.
#
# See also: ‥, …
# =============================================================================
# ∈ — collection membership (element in set)
#
# <expr> ∈ <列表>
#
# GRAMMAR:
# membershipExpr :← expr '∈' expr
#
# EXPECTED OUTPUT:
# none — stdout not pinned for this exemplum.
main {
const string condicio ← "agens"
const int aetas ← 21
# Basic ∈ with 文本 列表
if condicio ∈ ["pendens", "agens", "pausa"] {
print "condicio valida"
}
# ∈ with numeric 列表
if aetas ∈ [18, 21, 65] {
print "aetas insignis"
}
print "exempla ∈"
}radix/corpus/operatores/membership-range.fab (canonical · operator-group)#
Checks whether a value lies within a range.
# =============================================================================
# ∈ — Checks whether a value lies within a range
# =============================================================================
#
# What this teaches:
# • Checks whether a value lies within a range.
# • Related operators: ‥, …
#
# Common mistakes:
# • Confusing `∈` over a range (numeric interval) with `∈` over a collection (set membership) — the right operand decides: a range such as `0‥100` tests the interval, a 列表, 映射, or 集合 tests membership.
#
# See also: ‥, …
# =============================================================================
# ∈ — range containment (membership in a numeric interval)
#
# <expr> ∈ <initium>‥<finis> — half-open [initium, finis)
# <expr> ∈ <initium>…<finis> — inclusive [initium, finis]
# <expr> ∈ <initium> before <finis> — explicit exclusive end
#
# GRAMMAR:
# rangeMembership :← expr '∈' rangeExpr
#
# EXPECTED OUTPUT:
# none — stdout not pinned for this exemplum.
const int aetas = 25
main {
print "exempla ∈"
# Basic ∈ with ‥ operator (exclusive end)
if aetas ∈ 0‥100 {
print "aetas intra fines est"
}
# ∈ with … (inclusive end)
if aetas ∈ 18…65 {
print "aetas laboris"
}
# ∈ with before (explicit exclusive)
if aetas ∈ 0 before 18 {
print "minor"
}
}radix/corpus/operatores/membership-values.fab (canonical · operator-group)#
Checks whether a value is in a list, set, map key set, or enum value set.
# =============================================================================
# ∈ — Membership over lists, sets, map keys, and enum value sets (∈ and ∉)
# =============================================================================
#
# What this teaches:
# • `∈` is true when the left value is in the right collection; `∉` is its negation.
# • The right operand may be a list, a set, or a map (the test is on the keys).
# • An enum value set is a list of enum members: `c ∈ [Color.rubrum, Color.viridis]`.
#
# Common mistakes:
# • Using `∈` or `∉` with text on the right — they never apply to text; use `contains` for a substring test.
# • Using `∈` with a scalar, nullable, or unresolved empty `[]` right operand — each is rejected.
#
# See also: ‥, …
# =============================================================================
# ∈ / ∉ — membership in list, set, map key, and enum value set
#
# <expr> ∈ <列表 | 集合 | 映射 | [enum members]>
# <expr> ∉ <列表 | 集合 | 映射 | [enum members]>
#
# GRAMMAR:
# membershipExpr :← expr ('∈' | '∉') expr
#
# EXPECTED OUTPUT:
# list in
# list out
# set in
# set out
# map key in
# map key out
# enum in
# enum out
enum Color {
rubrum,
viridis,
caeruleum
}
fn classify(Color c) → void {
if c ∈ [Color.rubrum, Color.viridis] {
print "enum in"
}
if c ∉ [Color.rubrum, Color.caeruleum] {
print "enum out"
}
}
main {
# list
const list<int> primi ← [2, 3, 5, 7]
if 5 ∈ primi {
print "list in"
}
if 4 ∉ primi {
print "list out"
}
# set
var set<string> visi ← empty
visi.add("alpha")
visi.add("beta")
if "alpha" ∈ visi {
print "set in"
}
if "gamma" ∉ visi {
print "set out"
}
# map: the test is on the keys
var map<string, int> puncta ← empty
puncta["alpha"] ← 1
puncta["beta"] ← 2
const string present ← "beta"
const string absent ← "gamma"
if present ∈ puncta {
print "map key in"
}
if absent ∉ puncta {
print "map key out"
}
# enum value set: a list of enum members
classify(Color.viridis)
}Expected output:
list in
list out
set in
set out
map key in
map key out
enum in
enum out
radix/corpus/operatores/membership-decline.fab (supporting · reject)#
Membership reject harness: a scalar, nullable, unresolved empty list, text, or mixed value-set right operand is rejected.
# =============================================================================
# ∈ — membership decline (MG-6b)
# =============================================================================
# This exemplum intentionally fails to compile. The sibling .expected file
# pins only the stable diagnostic identities, not paths or rendered prose.
#
# Each statement below is one reject cell:
# • scalar right operand 1 ∈ 5
# • nullable collection right n ∈ maybe
# • unresolved empty list right 1 ∈ []
# • mixed enum/scalar value set c ∈ [Color.rubrum, 3]
# • text right operand "a" ∈ "abc" (membership never applies to
# text; use contains)
enum Color {
rubrum,
viridis
}
fn scalar() → void {
if 1 ∈ 5 {
print "scalar"
}
}
fn nullable(list<int> ∪ none maybe) → void {
if 1 ∈ maybe {
print "nullable"
}
}
fn unresolved() → void {
if 1 ∈ [] {
print "unresolved"
}
}
fn mixed(Color c) → void {
if c ∈ [Color.rubrum, 3] {
print "mixed"
}
}
fn text() → void {
if "a" ∈ "abc" {
print "text"
}
}
main {
scalar()
}Expected: compilation rejects this example.