1
Off Topic / Re: Python 2.7.3 Discussion
« on: 2012-Nov-09 »
Python is a very powerful language, interesting in that nothing is statically typed. Scripting support from within GLB would be interesting...
If you're interested in learning it, CS212 on Udacity is a very good course, and it gave me my favourite snippet:
so:
If you're interested in learning it, CS212 on Udacity is a very good course, and it gave me my favourite snippet:
Code: (glbasic) [Select]
def memo(f):
cache = dict()
def wrap(*args):
if args not in cache: cache[args] = f(*args)
return cache[args]
return wrap
memo: A function that takes in a function, and returns a function that has an inbuilt cache that stores the results of previous calls.so:
Code: (glbasic) [Select]
f = lambda x: x**2
f = memo(f)
# or this achieves the same thing:
@memo
def f(x):
return x**2