Rudolf Adamkovič Personal site


Destructuring

T ↦ P ≡ {K₁ V₁ K₂ V₂ …} ↦ {K₁ P₁ K₂ P₂ … CAPTURE?} syntax

Destructure table T.
Destructure Vᵢ to Pᵢ for every equal Kᵢ.
If Kᵢ is :, interpret it as key "Pᵢ" literally.
If Kᵢ stars with ?, also match nil.
If CAPTURE is &as T*, set T* to T.
Gotcha: {} matches any table, not the empty table.

T ↦ P ≡ [V₁ V₂ … Vₙ] ↦ [P₁ P₂ … Pₘ CAPTURE?] syntax

Destructure a sequence from table T.
Destructure Vᵢ to Pᵢ for every i ≤ m.
If CAPTURE is &as T*, set T* to T.
If CAPTURE is & T*, set T* to [Tₙ₊₁ … Tₘ].
Gotcha: [] matches any table, not the empty table.

V ↦ P ≡ (values V₁ V₂ … Vₙ) ↦ (P₁ P₂ … Pₘ) syntax

Destructure multiple values.
Destructure Pᵢ to Vᵢ for every i ≤ m.
Gotcha: Multiple values cannot be nested.

X ↦ E base case syntax

If E is literal, check X = E.
If E is identifier, bind E to X (†).
(†) If not documented otherwise, such as in match.

X ↦ _ convention

Ignore E.
Also _E for any E.


© 2025 Rudolf Adamkovič under GNU General Public License version 3.
Made with Emacs and secret alien technologies of yesteryear.