wyvernlang/wyvern

support multi-line lambdas

Closed this issue · 2 comments

It would be nice to support multi-line lambdas.

This is involved, however. The problem is that multi-line lambdas would naturally be implemented with an indented sequence of statements. However, lambdas naturally go inside parentheses, and the lexer does not try to track indentation inside parentheses. Changing the lexer would probably complicate the specification.

This would be a critical issue if we didn't have indented blocks for "if" and "match" cases. As it is, it doesn't seem so bad.

Random idea: re-use ~. Thus:

collection.map(x -> ~)
    val y = x+1
    y

This is a silly example, but it illustrates the idea. Since type Int doesn't have a TSL, we could default into making the TSL just Wyvern code (though in the case where there is a TSL for a type, this couldn't be used, perhaps unexpectedly--perhaps a drawback of this idea). Note that x is bound in the TSL below, as well as other variables that are in scope.

We could eliminate the ambiguity by allowing '~~' to mean 'use Wyvern code in the indented section rather than expecting some TSL'

So having seen a lot of JavaScript code recently with promises and lambdas everywhere, we should be very careful making syntax decision here as none is perfect. JS results in a lot of ways to express the same thing (lambda). We may potentially have the same problem. Do we want lambdas to stand out in the code or be a very simple in-line thing? What if we have many nested lambdas (like JS does all the time!) - do we want the scopes to be obvious to the user? Especially if we utilise indentation instead of parentheses? :-( No easy answer here but potential for exploratory project!