Hi Adrian, I wrote some code to do this a few releases ago. It's the cached_method decorator in Sage. Here's your example:
sage: class dog(): ....: def __init__(self, bark='guau'): ....: self._bark = bark ....: @cached_method ....: def bark(self): ....: sleep(5) ....: return (self._bark + " ")*3 ....: sage: sparky = dog() sage: sparky.bark() #5 seconds 'guau guau guau ' sage: sparky.bark() #instant 'guau guau guau ' If you're curious, you can find the code in sage/misc/cachefunc.py --Mike --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---
