That is where I got to really. Ability to construct one’s own expressions, where evaluation can be controlled. And found out that deferred evaluation is what would potentially provide exactly what is needed for this.

Making use of ‘function’ protocol seems appropriate as I don’t think inventing any extensive syntax is justified.

from lazy_object_proxy import Proxy

value = Proxy(lambda: expr())
# If this could be written in a more concise form. e.g.:
value = `expr()`
# then it would be worthwhile constructing and making use of VB-like expressions
def IF(condition, when_true, when_false):
    if condition:
        return when_true
        return when_false

def expr1():
    return 1

def expr2():
    return 2

result = IF(True, `expr1()`, `expr2()`)
# Expressions would only be evaluated when certain usage takes place
# This works fairly nicely, but inconvenience of it is a dealbreaker (to be used for such cases)
result = IF(True, Proxy(lambda: expr1()), Proxy(lambda: expr2()))
# Not yet evaluated
print(result + 1)
# Now it is
Also, can't find a way to ONLY force evaluation without any additional operations in this specific library. A simple callable which evaluates if unevaluated & returns would do. Then:

def IF(condition, when_true, when_false):
    if condition:
        return ensure_eval(when_true)
        return ensure_eval(when_false)
Controls evaluation if deferred objects are provided, but can also be used with `normal` values.

On 20 Jul 2023, at 22:51, Random832 <> wrote:

On Mon, Jul 17, 2023, at 16:41, Dom Grigonis wrote:
Would be interesting to see if my preference is an outlier or not really.

I think this is a false dichotomy. We should consider VB-like conditional expressions if(condition, when_true, when_false) as well.
Python-ideas mailing list --
To unsubscribe send an email to
Message archived at
Code of Conduct: