Aside from the type conversion dunders (e.g. `__bool__`), and the `and`, `or` 
and `in` operators, this is possible right now: 
You can create a `Symbol` class that returns another `Symbol` in the compatible 
operator dunder methods, while internally maintaining a list of (operator, 
args, kwargs). Then you can "replay" all the operations when you evaluate the 
symbol by in some way binding it to a value. You could even go as far as to 
build an AST from the operations list, and compile it to a function or lambda 
(its argument is the value you bind to), so you avoid the (significant) 
overhead of looping through the operations and applying then.

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.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/EK6F7RZQW7G5N4LDSNAB7AONUB2TPAKZ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to