3 ms·
Python’s `lambda` can only contain a single expression. There’s no good way to add support for full anonymous functions to Python’s grammar. One of the rules t
by pansa2 6y ago
Python’s `lambda` can only contain a single expression.
There’s no good way to add support for full anonymous functions to Python’s grammar. One of the rules that makes significant-whitespace work elegantly is that statements can contain expressions, but never vice-versa.
- omaranto 6y agoPlenty of languages with significant-whitespace have multiline anonymous functions, like Haskell, Standard ML, Ocaml, etc. Maybe it's no possible in Python for a student reason, but the reason is not that the syntax is bad on indentation.
- pansa2 6y agoThe syntaxes of those languages are fundamentally different from Python’s. They don’t have an “expressions may not contain statements” rule - they don’t even have statements.
- omaranto 6y agoIt sounds like you agree with me: the reason Python does not have multiline lambdas is not that it has significant-whitespace, but other decisions including the “expressions may not contain statements” rule.
- c-cube 6y agoNitpick : neither ocaml nor SML have significant whitespace.
- omaranto 6y agoYou're right! It's been too long since I used them. I think I was probably remembering F#'s light syntax.