LAMBDA UDTs use LAMBDA to define custom data types that emulate the object-oriented programming paradigm.
A user-defined type (UDT) combines fields and methods into a structured term.
Overview
LAMBDA UDTs follow the general form:
lambda(i, choose(i, a, b, ...))Data is encapsulated inside a number of user-defined fields, listed as a,b... in the expression above.
These fields can contain any term except for primitives.
In essence, LAMBDA UDTs allow users to define composite data structures that can serve as both inputs and outputs for user-defined functions.
Instantiation
UDTs must be instantiated with specific field values before they can be used.
They can be instantiated manually or via a constructor pattern:
=let(
udt,lambda(a,b...,
lambda(i,choose(i,a,b...))
),
udt(a,b...)
)The expression above creates an instance of the type udt.
Note that the resulting value is a lambda term; it cannot be directly displayed in a cell.
Field access
To access a stored field, provide an index argument to the instantiated term:
=let(
udt,lambda(a,b...,
lambda(i,choose(i,a,b...))
),
udt(a,b...)(<index>)
)This applies the index via β-reduction, returning the field corresponding to that index.
Notes
- Calculation limits represent a major limitation to LAMBDA UDTs, as they are heavily LAMBDA-intensive in nature and can quickly hit the recursion limit.