Skip to content

Instantly share code, notes, and snippets.

cache = {}
def memoize(func):
"This is a decorator."
def _inner(num):
if num in cache:
value = cache[num]
else:
value = func(num)
cache[num] = value
function_map = {}
def register_doer(name):
"This is a decorator factory. It should create and return a decorator"
def inner(func):
function_map[name] = func
return func
return inner
@register_doer("Do Flibble!")
(import [collections [OrderedDict]])
(defn lru-cache [&optional [limit 100]]
(defn inner [func]
(setv cache (OrderedDict))
(defn cached-fn [&rest args]
(let [[result nil]]
(try
(setv result (.pop cache args))
(catch [e KeyError]