Closure
In JavaScript, we can create closure like this,
[code language=“javascript”] var foo = (() => { let x = 0; return () => { return x++; } })();
for (var i = 0; i < 10; i++) { var x = foo(); console.log(x); } [/code]
But translating above code into C++, it cannot work as expected for the variable, unless the variable is outside the lambda function.
[code language=“cpp”] // In a function int x; // variable here auto foo = [&x]() { x = 0; return [&x]() { return x++; }; }(); for (int i = 0; i < 10; i++) { int x = foo(); cout « x « endl; } [/code]
Using Python as the most powerful calculator
Once I was looking for “expression calculator”. The expression calculator is different from normal calculator like calc.exe, which cannot use variable freely as algebra. But the expression calculator, we can predefine a variable with a value, then evaluate the variables in algebraic expression. It is very useful. My favourite expression calculator is SpeedCrunch.
Then, recently, I want to test a math function in SpeedCrunch, but this is impossible, since expression calculator can only define the variable, but not define a function. I remembered the title of Python Tutorial, “Using Python as a Calculator”. Yes, expression calculator, with ability to define function, then Python will be the one.
Comic Downloader alpha stage
I wrote several Greasemonkey userscripts. However, the Javascript has its own limitation for security reason, especially when a website uses scripts from cross domain. As a result, Javascript cannot get the information, and my userscript fails to work. Therefore, I start another project, in order to solve the cross domain problem using Python, and targeted on Linux (Ubuntu).
The current development stage is alpha, and targeted only on one website, since the other websites I frequently visit still work with Greasemonkey userscript. The alpha stage of Comic Downloader is currently work in command-line. GUI feature will be added in future with PyGTK. Currently, the command-line is able to solve my problem for offline comic reading.