5 ms·
In python, lambda usage extremly beautiful. Also, 'lambda' keyword solves readibility problem. I expected a keyword. Is there any challenge to add keyword?
by cengizkrbck 12y ago
In python, lambda usage extremly beautiful. Also, 'lambda' keyword solves readibility problem.
I expected a keyword. Is there any challenge to add keyword?
- VMG 12y agoBackwards compatability. Old valid code should remain valid. That includes code which calculates wavelengths.
- thelinked 12y agoAn interesting example of C++ not being able to introduce new keywords is the co-opting of auto in C++11 from a storage class to type deduction.
- ninkendo 12y agoBut they had a decent justification: the auto keyword literally did nothing in C++. The only place it was valid, it was also the default.
- danielweber 12y agoIIRC they audited a bunch of projects to see if anyone was using auto somewhere besides test code explicitly for the auto-keyword, and found nothing.
- deleted 12y ago[deleted]
- TillE 12y agoNot shown in this article are all the things you can do within the [] (typically just [&] or [=]), which turns a simple lambda into a closure. The syntax is a bit arcane, but it does what it needs to. They could've stuck a "lambda" keyword in front of it all, but it's not necessary, and making a new keyword always has the potential to break old code.
- guidopallemans 12y agois it possible to do #define lambda [] ?
- Kronopath 12y agoI think that's possible, but I would strangle anyone who actually did that. At that point, not only are you pointlessly redefining the language just so it can feel slightly more familiar to people who are more comfortable with Python and the like, but you also completely lose the ability to enclose variables in the square brackets to make a closure. If you're going to write C++, then write C++. Don't redefine language constructs to fit the patterns of your other favourite language.
- leni536 12y agoI think you can #define begin { #define end } too. I would not suggest it though.
- kps 12y agoThat way lies http://minnie.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/cmd/sh/mac.h http://minnie.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/cmd/...
- leni536 12y agoI don't like that in python you are enforced to only use a single expression in lambda. Sure, writing long lambda functions is ugly but I don't think python should enforce a given coding style in the language level.
- crazypyro 12y agoIsn't that literally a core principal of Python? They enforce all kind of coding styles within the language, not the mention all the PEPs.
- leni536 12y agoBut PEPs are not enforced in the language level. Also there are cases where there could fit two simple expression in a lambda. Also the language still doesn't stop you from abusing lambdas, you can nest them. It could be stated in one of the PEPs that "no overly complicated lambdas" and that's it, there is no need for the language to enforce this.
- crazypyro 12y agoPEPs are literally the language, in my opinion. It may not be enforced on an implementation level, but some have been. You can't mix spaces and tabs now. That seems like a style choice being enforced on every level.
- crazypyro 12y agoPEPs are literally the language, in my opinion. It may not be enforced on an implementation level, but some have been. You can't mix spaces and tabs now. That seems like a style choice being enforced on every level.
- tel 12y agoThat also dramatically reduces the value of lambdas. Without that limitation then they work as anonymous blocks of any complexity.
- rbonvall 12y ago