Skip to content

Instantly share code, notes, and snippets.

@CMCDragonkai
Last active April 11, 2020 10:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CMCDragonkai/fe145ce553d77e4fb789a7a6e1240d5d to your computer and use it in GitHub Desktop.
Save CMCDragonkai/fe145ce553d77e4fb789a7a6e1240d5d to your computer and use it in GitHub Desktop.
Self-Referential/Recursive Dictionary in Strict Languages #python #javascript

Self-Referential/Recursive Dictionary in Strict Languages

The problem with this in strict languages is that we keep needing lazy annotations.

And the other problem is that this won't be very fast in strict languages.

In strict languages there is probably no caching of the function calls.

What this means is comparing a recursive dictionary to a static dictionary, the recursive dictionary is going to be slower depending on how many function calls there are. In fact the slow down may be linear to the number of self or that function calls.

It would work great for IoC containers though if the function calls could be cached.

const Y = f => (x => x(x))(x => f(y => x(x)(y)))
const container_ = (that) => () => ({
a: () => that().b(),
b: () => 3,
});
const container = Y(container_)();
console.log(container.a());
console.log(container.b());
Y = lambda f: (lambda x: x(x))(lambda y: f(lambda *args: y(y)(*args)))
d1 = lambda self: lambda: {
'a': lambda: 3,
'b': lambda: self()['a']()
}
# fix the d1, and evaluate it
d2 = Y(d1)()
# to get a
d2['a']() # 3
# to get b
d2['b']() # 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment