Destructuring
T ↦ P ≡ {K₁ V₁ K₂ V₂ …} ↦ {K₁ P₁ K₂ P₂ … CAPTURE?}
syntax- Destructure table
T
.
DestructureVᵢ
toPᵢ
for every equalKᵢ
.
IfKᵢ
is:
, interpret it as key"Pᵢ"
literally.
IfKᵢ
stars with?
, also matchnil
.
IfCAPTURE
is&as T*
, setT*
toT
.
Gotcha:{}
matches any table, not the empty table. T ↦ P ≡ [V₁ V₂ … Vₙ] ↦ [P₁ P₂ … Pₘ CAPTURE?]
syntax- Destructure a sequence from table
T
.
DestructureVᵢ
toPᵢ
for everyi ≤ m
.
IfCAPTURE
is&as T*
, setT*
toT
.
IfCAPTURE
is& T*
, setT*
to[Tₙ₊₁ … Tₘ]
.
Gotcha:[]
matches any table, not the empty table. V ↦ P ≡ (values V₁ V₂ … Vₙ) ↦ (P₁ P₂ … Pₘ)
syntax- Destructure multiple values.
DestructurePᵢ
toVᵢ
for everyi ≤ m
.
Gotcha: Multiple values cannot be nested. X ↦ E
base case syntax- If
E
is literal, checkX = E
.
IfE
is identifier, bindE
toX
(†).
(†) If not documented otherwise, such as inmatch
. X ↦ _
convention- Ignore
E
.
Also_E
for anyE
.