Inline functions with non-local returns
The basic idea is to have lambdas with return statements that return from the enclosing function. Here's a possible syntax:
delegate void IterationFunction (int i);
inline void iterate_characters (ParsingContext context, IterationFunction fn) {
var start = context.i;
while (context.i < context.text.length) {
fn (context.i);
context.i++;
}
}
void lex_text (ParsingContext context) {
var start = context.i
iterate_characters (context, i => { // the whole call will get inlined
char c = text[context.i];
switch (c) {
case '\n':
context.tokens.add (Token (Location.start_to_end (start, context.i)));
return@lex_text; // returns from lex_text, instead of the lambda
default: do_stuff ();
}
});
}
Kotlin has it and it's rly neat
Edited by Rico Tzschichholz