Hacker News new | past | comments | ask | show | jobs | submit login

> So Python doesn't have that issue because it doesn't overload braces for hashes and blocks.

Yes, and also because lambdas in Python can only have expression bodies, not statements. That means you can never have a statement nested inside an expression. This is important because Python's rule to ignore all newlines between parentheses would fall apart if you could stuff a statement-bodied function inside a parenthesized expression.




Yes the lambda issue is something I ran into for Oil. Although this part of the language is deferred, the parser is implemented:

    # Ruby/Rust style lambda, with the Python constraint that the body can only be an expression
    var inc = |x| x + 1

    # NOT possible in Oil because | isn't a distinct enough token to change the lexer mode
    var inc = |x| {
      return x + 1
    }

    # This is possible but I didn't implement it.
    # "func" can change the lexer mode so { is known to start a block.
    # In other words, { and } each have two distinct token IDs.

    var inc = func(x) {
      return x + 1 
    }
I think this is a decent tradeoff, but it's indeed tricky and something I probably spent too much time thinking about ... the perils of "familiar" syntax :-/




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: