News for hackers. Stuff that matters.
Re:Lambdas and Functions in Python by mastro35 on Saturday June 16, 2018 @05:40PM (#17329598)
Well, actually I find the last code far better and easier than the original one. As I wrote in the article, if you want to add a factorial method you just need to change the catalog of the function provided by adding this line

“!”: lambda x: math.factorial(x),

However, it’s probably a matter of taste... but I do like the last code more. :)

Re:Lambdas and Functions in Python by adjkant on Saturday June 16, 2018 @06:06PM (#17329727)
I'm a big fan of first-class functions (or similar) and functional code, but lambdas are in the end just syntactic sugar. Why not just write:

"!": math.factorial,

The lambda wrapper isn't doing anything here.

Re:Lambdas and Functions in Python by guitarbill on Saturday June 16, 2018 @06:38PM (#17329864)
I also thought that, but `math.factorial` is a builtin, and so you cannot get the signature of it, and the code can't determine how many operands the command needs. This is similar to the `self.stack.clear()` example. (`signature(math.factorial)` gives "ValueError: no signature found for builtin <built-in function factorial>")