Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Provisional API: This reference documents current compiler behavior. Compatibility is not yet promised.

src/components/lambda-functions.x

Lambda lowering.

Design notes

A lambda becomes a static function among the unit’s support declarations. Its parameters keep their declarators, a bare one is a Var, and it returns a Var: a bare return and the end of a block body return none, and an expression body returns its value. A noncapturing lambda’s value is that function.

A capturing lambda’s function also takes each binding it captures, a value as its own type and a reference as a reference. Its value is a Func that copies each captured value, or the address a reference captures, into a context record when the lambda is evaluated, left to right. The Func’s adapter reads the arguments and calls the function with them and the record’s fields. A public inline function reaches the unit’s private record through a bridge function.

A local or parameter that a lambda shares by reference moves into a Scope cell, so it outlives the function that declares it; a function rule rewrites each function definition whose lambdas share one.

Each definition precedes the definitions that call it: the compiler settles whether a linked copy reaches a compile-time operation when the copy binds.