-
Notifications
You must be signed in to change notification settings - Fork 0
Recursive Destructuring
Andrew Matthews edited this page Aug 14, 2025
·
2 revisions
This shows fifthlang’s recursive destructuring in function parameters using a simple calculate_bmi example. This capability (destructuring directly in parameter lists with nested property bindings) is not currently available in C#.
// Destructure Person -> Vitals -> Height/Weight right in the parameter list
calculate_bmi(p: Person {
name: Name,
vitals: Vitals{
age: Age,
height: Height,
weight: Weight
}
}) : float {
return weight / (height * height);
}
- The parameter pattern unwraps Person into local variables name, height, and weight
- vitals is destructured recursively to access nested properties
- No boilerplate reads like p.Vitals.Height; the signature binds exactly what the function needs
class Person {
Name: string;
Vitals: Vitals;
}
class Vitals {
Height: float;
Weight: float;
}
main(): float {
// assume p: Person is available
return calculate_bmi(p);
}
- C# supports deconstruction and rich pattern matching, but not destructuring directly in function parameter lists
- fifthlang lets you bind nested properties at the boundary (the function signature) so your body stays minimal and intention-revealing
- Names and nesting in the pattern must match the input type
- This feature is under active development; see tests around recursive destructuring for the most current behavior