The real reason to not use lambdas in python is that they’re arbitrarily crippled. Also, why are they lambda and not def? Why don’t they support names? etc., etc. Guido just crippled them and it really makes Python worse for it.
Is there actually a reason why lambda can't have a block-level type syntax instead of just being inline, limited to a single expression? Like in JavaScript arrow functions:
() => {
statement 1;
statement 2;
...
}
I'm not sure if there is something in the language that would make it really difficult or impossible to implement, or Guido was just against it (and also, now that Guido is not the BDFL any longer, could there be a change of vision with regards to how some of these things are perceived and what should and shouldn't make it into the language?)
Curly brackets are already used for set/dict literals so you can’t use that (a theoretical improved lambda should allow for returning a dict literal without having to use double brackets). Python blocks are purely whitespace based, but whitespace is ignored in the middle of brackets, like for a function call. So you need a syntax for blocks that isn’t white-space based and doesn’t look too different from normal python.
2
u/david2ndaccount Sep 27 '18
The real reason to not use lambdas in python is that they’re arbitrarily crippled. Also, why are they lambda and not def? Why don’t they support names? etc., etc. Guido just crippled them and it really makes Python worse for it.