Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Python lambdas are just syntactic sugar for creating a function object. The ast can just build a named function and use it in the needed expression.


However, that approach seems rather backwards compared to having an anonymous function primitive which is used as the basis for the lambda one-line-only sugar, as well as named functions (which simply establish a binding between a name and the anonymous thing).


Why should the programmmer care about whether the underlying function is named or not?


I imagine some kind of analogue to gensym would work there. The name can be throw away and guaranteed unique in scope.

In fact, a lot of SICP examples have you define a function within a function with a name like "iter" for TCO recursion. It'd work like that.

Edit: seems like gyka below confirms that's how it works. I should have read on!




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

Search: