Created
December 14, 2010 02:33
-
-
Save slpsys/739920 to your computer and use it in GitHub Desktop.
A magical journey through bullshit.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> weight | |
10 | |
>>> a | |
[1, 2, 3] | |
# ok, we have a nice list here. let's apply a map() to see if we can raise the power of all values: | |
>>> map((lambda x: x**2), a) | |
[1, 4, 9] | |
# sweet, it works! ok, now let's try to fold in your example of iterating and incrementing: | |
>>> map((lambda x: weight += x), a) | |
File "<stdin>", line 1 | |
map((lambda x: weight += x), a) | |
^ | |
SyntaxError: invalid syntax | |
# b..but.. | |
>>> what | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in ? | |
NameError: name 'what' is not defined | |
# ok, well. maybe `lambda` in Python is not a closure, which would mean it doesn't have access to the surrounding stack frame and all its variables. | |
>>> map((lambda x: x + weight), a) | |
[11, 12, 13] | |
# a;dfkjasdf;lkasjdf ok, it is an actual closure. that's annoying. let's..hm. _how about reduce()_? we know from Lisp that transforms a vector to a scalar.. | |
>>> reduce((lambda x,y: x + y), a) | |
6 | |
# yay, it works! | |
>>> exit | |
'Use Ctrl-Z plus Return to exit.' | |
# ok, you can just fuck right along now. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment