3 ms·
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
by mastro35 8y ago
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. :)
- adjkant 8y agoI'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.
- guitarbill 8y agoI 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>")