Skip to content

Instantly share code, notes, and snippets.

@orivej
Last active October 31, 2017 16:19
Show Gist options
  • Save orivej/5fddcf792dfa37a5bfa16d9a95fe70fa to your computer and use it in GitHub Desktop.
Save orivej/5fddcf792dfa37a5bfa16d9a95fe70fa to your computer and use it in GitHub Desktop.
A model of an imperative interpreter of a pure language composing overlays
let
f = final: previous: { a = "fa"; b = "fb"; };
g = final: previous: { a = previous.a + final.b; };
h = final: previous: { b = "hb"; };
in let
current0 = { };
current1 = current0 // f final current0;
current2 = current1 // g final current1;
current3 = current2 // h final current2;
final = current3;
in
final.a
# This models an imperative interpreter of a pure language composing overlays.
def f(final, previous):
return {
'a': lambda: 'fa',
'b': lambda: 'fb',
}
def g(final, previous):
return {
'a': lambda: previous['a']() + final['b'](),
}
def h(final, previous):
return {
'b': lambda: 'hb',
}
final = {}
current = {}
for func in f, g, h:
own = func(final, current)
current = current.copy()
current.update(own)
final.update(current)
print(final['a']())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment