aima/utils.py
def memoize(fn, slot=None):
    """Memoize fn: make it remember the computed value for any argument list.
    If slot is specified, store result in that slot of first argument.
    If slot is false, store results in a dictionary."""
    if slot:
        def memoized_fn(obj, *args):
            if hasattr(obj, slot):
                return getattr(obj, slot)
            else:
                val = fn(obj, *args)
                setattr(obj, slot, val)
                return val
    else:
        def memoized_fn(*args):
            if not memoized_fn.cache.has_key(args):
                memoized_fn.cache[args] = fn(*args)
            return memoized_fn.cache[args]
        memoized_fn.cache = {}
    return memoized_fn
def memoize(fn, slot=None):
    """Memoize fn: make it remember the computed value for any argument list.
    If slot is specified, store result in that slot of first argument.
    If slot is false, store results in a dictionary."""
    if slot:
        def memoized_fn(obj, *args):
            if hasattr(obj, slot):
                return getattr(obj, slot)
            else:
                val = fn(obj, *args)
                setattr(obj, slot, val)
                return val
    else:
        def memoized_fn(*args):
            if not memoized_fn.cache.has_key(args):
                memoized_fn.cache[args] = fn(*args)
            return memoized_fn.cache[args]
        memoized_fn.cache = {}
    return memoized_fn
def memoize ( fn , slot = None ) : if slot : def memoized_fn ( obj , * args ) : if hasattr ( obj , slot ) : return getattr ( obj , slot ) else : val = fn ( obj , * args ) setattr ( obj , slot , val ) return val else : def memoized_fn ( * args ) : if not memoized_fn . cache . has_key ( args ) : memoized_fn . cache [ args ] = fn ( * args ) return memoized_fn . cache [ args ] memoized_fn . cache = { } return memoized_fn
Memoize fn: make it remember the computed value for any argument list.
    If slot is specified, store result in that slot of first argument.
    If slot is false, store results in a dictionary.
Memoize fn : make it remember the computed value for any argument list . If slot is specified store result in that slot of first argument . If slot is false store results in a dictionary .