Thursday, January 24, 2008

A quick note about python.

People anxious understanding lambda functions, take a look at this code:

#!/usr/bin/env python

# Define nameless (lambda) function.
# This means that we:
# a) Create a function object.
# b) Assign "f" a reference to this object (function).
f = lambda x: x+42

# Call this function, passing it 1 variable.
print f(0)


# Do the same thing, simply replace the nameless with a "FULL" function.
def func(x):
return x + 42

# Assign variables "g" a reference to function "func"
g = func

# Call this function, passing it 1 variable.
print g(0)