3 ms·
I might not have understood it correctly. I thought you were thinking of: def bar(x): def X(): return 1 def Y(): return 1 def Z(): return b
by compressedgas 6y ago
I might not have understood it correctly. I thought you were thinking of:
def bar(x):
def X(): return 1
def Y(): return 1
def Z(): return bar(x-1) + bar(x-2)
table = {0:X,0:Y}
default = Z
return table.get(x, default)()
Whereas I was thinking of:
def X(x):
def X(): return 1
return X
def Y(x):
def Y(): return 1
return Y
def Z(x):
def Z(): return bar(x-1) + bar(x-2)
return Z
table = {0:X,1:Y}
default = Z
def bar(x):
return table.get(x, default)(x)()
Which can be reduced to a tabled indirect jump:
def bar(x):
jump by x via table T and default D where T = {0:X,1:Y} and D = Z
X: return 1
Y: return 1
Z: return bar(x-1) + bar(x-2)