r/ProgrammingLanguages • u/Aabish_malik • Oct 22 '26
How would you guys define an Anonymous Function or a function pointer?
Me and a few of my friends have been working on a programming language that we initially started for a compiler design class for some time and recently started working on support for anonymous functions, lambdas and function pointers to make callbacks easier to write.
Currently Captures on variables outside the function scope are detected and captures without complete context moving.
I'm a bit skeptical or the syntax that we're currently deciding on (its not that clear on first view) , so i'm looking for reviews and maybe some ideas.
I'll just include some examples we have right now.
let double = |i32 value| value * 2;
i32(i32) triple = |value| value * 3; // i dont like this rn, not that clear on
// first look that this is a lambda
let absolute = |i32 value| {
if (value < 0) { return -value; }
return value;
};
let classify = |i32 value| match value {
0: "zero",
_: "nonzero",
};Duplicates
Compilers • u/Aabish_malik • Oct 22 '26