
May 25, 2021
4 a.m.
On Mon, May 24, 2021 at 09:49:13PM -0000, Joren wrote:
It's unfortunate that there is no way to have e.g. `'spam' in my_symbolic_set` evaluate to something else than a boolean. Also, this approach will not work with everything else for which there is no dunder method, e.g. `math.sin(my_symbolic_value)` cannot be tricked into returning a Symbol.
Monkey-patching to the rescue. import math from math import sin as _sin def my_sin(x): if isinstance(x, Symbol): ... else: return _sin(x) math.sin = my_sin Obligatory link to: https://avdi.codes/why-monkeypatching-is-destroying-ruby/ -- Steve