Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #A function is "consistent" if it always returns the same value for the same arguments.
- #A function can be consistent even if it is not:
- # - deterministic
- # - free of side effects
- #That said, "F is deterministic and F is free of side effects" does imply "F is consistent"
- #consistent, deterministic, no side effects
- def a(x):
- return x * 2
- #consistent, deterministic, has side effects
- _cache = []
- def b(x):
- _cache.append(x)
- return x
- #consistent, not deterministic, no side effects
- #(pointless, yes, but still possible)
- def c(x):
- if true_random.choice((False, True)):
- return x
- else:
- return x
- #consistent, not deterministic, side effects
- _cache = []
- def d(x):
- _cache.append(x * true_random.random())
- return x
- #not consistent, deterministic, no side effects
- def e(x):
- #... Pretty sure this one is impossible actually
- pass
- #not consistent, deterministic, has side effects
- _cache = []
- def f(x):
- _cache.append(x)
- return len(_cache)
- #not consistent, not deterministic, no side effects
- def g(x):
- return x * true_random.random()
- #not consistent, not deterministic, has side effects
- _cache = []
- def h(x):
- _cache.append(x * true_random.random())
- return len(_cache)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement