Lambda

Overview

lambdas are anonymous functions.

The syntax to create them is simple:

\ variable0 variable1 ... {  your code here }

You can even use it to

Call a function just once

\ i { <<< "passed '", i, "'" >>>; }(3);

Short lambdas

if the lambda consists of only one expression, the result of that expression is implicetely returned. Notice there is no semicolon in the lambda body;

<<< \ { 42 }() >>>;

Use case

Passing to a function pointer

funptr void fptr_t(int);
\ i { <<< "passed '", i, "'" >>>; } @=> var fptr_t fptr;
fptr(4);

As Argument to Functions

funptr void fptr_t(int);
fun void test(fptr_t fptr) {
   fptr(5);
}
test(\ i { <<< "passed '", i, "'" >>>; });
built with mdr and mdBook
You'll find the source here, Luke! note: privacy guards may interfere with the playground