6.5. LINQ fold macros (_fold / _old_fold)
The LINQ_FOLD module provides the _fold and _old_fold call macros
that rewrite LINQ pipelines into optimized loop forms — _fold is the
active fusion macro, _old_fold is a frozen pre-rewrite baseline kept
for benchmark comparison as _fold evolves toward splice-mode fusion.
The dispatch infrastructure (linqCalls table, fold_* helpers,
fold_linq_default) is private to this module; only the two macros
are user-facing. daslib/linq_boost re-exports them via
require daslib/linq_fold public so existing call sites that
require daslib/linq_boost continue to resolve _fold(...) without
change.
See also LINQ for the underlying query operations and Boost module for LINQ for the surrounding macro family.
All functions and symbols are in “linq_fold” module, use require to get access to it.
require daslib/linq_fold
Example:
require daslib/linq
require daslib/linq_boost
[export]
def main() {
let arr = [1, 2, 3, 4, 5]
let n = _fold(each(arr)._where(_ > 2).count())
print("{n}\n")
}
// output:
// 3
6.5.1. Call macros
- _old_fold
Frozen pre-rewrite baseline of _fold. Same expansion as _fold
today; the two diverge only when later PRs add splice-mode fusion to
_fold. Benchmarks compare _fold vs _old_fold to track
performance work — _old_fold must keep producing the historical
shape so the comparison stays meaningful.
for example:
_old_fold(each(foo)._where(_ > 5)._select(_ * 2))
- _fold
implements _fold(expression) that folds LINQ expressions into optimized sequnences for example:
_fold(each(foo)._where(_ > 5)._select(_ * 2))
expands into a single comprehension that does all operations in one pass