evhub / coconut

Simple, elegant, Pythonic functional programming.
http://coconut-lang.org
Apache License 2.0
4.05k stars 120 forks source link

Statement lambdas don't support "full statements"? #845

Closed Abrackadabra closed 2 weeks ago

Abrackadabra commented 1 month ago

Hi,

Loving the language!

The docs on statement lambdas say that

statement can be an assignment statement or a keyword statement

and

Statement lambdas support full statements rather than just expressions and allow for the use of pattern-matching function definition

But I might be misunderstanding what that means exactly, since I'm getting syntax errors on any statement lambda that contains what Python's grammar defines as a compound statement, namely

compound_stmt:
    | function_def
    | if_stmt
    | class_def
    | with_stmt
    | for_stmt
    | try_stmt
    | while_stmt
    | match_stmt

So per docs something like this should work, but doesn't

def () => if True: pass
evhub commented 1 month ago

Yeah, the docs should be more clear there—statement lambdas don't support multi-line statements that open a block below them (so basically any statement that ends in a colon), primarily because there isn't a nice syntax to handle them, as statement lambdas can appear inside of parentheses and whitespace inside of parentheses is supposed to be ignored.