Here's the proposal: Memo(), a glom memoization primitive.
On each top-level glom execution, Memo() would reset.
Here's a rough implementation:
class Memo:
def __init__(self, spec):
self.spec = spec
def glom(self, target, scope):
glom_globals = scope[ROOT]
if self not in glom_globals:
glom_globals[self] = ({}, {})
val_memo, id_memo = glom_globals[self]
try:
hash(target)
except:
memo, memo_key = id_memo, id(target)
else:
memo, memo_key = val_memo, target
if memo_key not in memo:
memo[memo_key] = scope[glom](target, self.spec, scope)
return memo[memo_key]
Motivation:
allow for safe traversal of self-recursive data structures -- Memo(Ref(Match(Switch(...)))) would be able to safely unzip a into a self-recursive data structure -- memoization would result in a self-recursive output of a similar shape to the input
Here's the proposal: Memo(), a glom memoization primitive.
On each top-level glom execution, Memo() would reset.
Here's a rough implementation:
Motivation:
Memo(Ref(Match(Switch(...))))
would be able to safely unzip a into a self-recursive data structure -- memoization would result in a self-recursive output of a similar shape to the input