Skip to content

Instantly share code, notes, and snippets.

@patrickbeeson
Created January 28, 2015 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patrickbeeson/b2505a7de937ec9d963b to your computer and use it in GitHub Desktop.
Save patrickbeeson/b2505a7de937ec9d963b to your computer and use it in GitHub Desktop.
Python Callables with Hysterersis
>>> class Factorial(Callable):
... def __init__(self):
... self.previous = {}
... def __call__(self, n):
... if n not in self.previous:
... self.previous[n] = self.compute(n)
... return self.previous[n]
... def compute(self, n):
... if n == 0 : return 1
... return n*self.__call__(n-1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment