Another way to avoid clumsy lambdas, while adding new functionality
The tentatively proposed idea here is using dollar signed expressions to define 'bills'. A bill object is essentially an expression which can be evaluated any number of times, potentially in different scopes. The following expression [a bill literal] would be pointless, but would define a bill that always evaluates to 1. $1 So, eval($1)==1. Some better examples... * assign a bill to `a` so that `a` will evaluate to the value of the name `foo` any time that `a` is evaluated, in the scope of that evaluation a = $foo * as above, but always plus one a = $foo + 1 * make `a` a bill that evaluates to the value of the name `foo` at the time that `a` is evaluated, in that scope, plus the value of `bar` **at the time and in the scope of the assignment to `a`** a = $foo + bar Note. Similarly to mixing floats with ints, any expression that contains a bill evaluates to a bill, so if `a` is a bill, `b=a+1` makes `b` a bill too. Passing a bill to eval should be the obvious way to get the value. The point? It allows functions to accept bills to use internally. The function would specify any names the bill can reference in the function's API, like keywords. def f(b): # the bill arg `b` can reference `item` for item in something: if eval(b): return True f($item < 0) You could also use a function call, for example `$foo()` would evaluate to a bill that evaluates to a call to `foo` in the scope and at the time of any evaluation of the bill. I've no idea if this is even possible in Python, and have no hope of implementing it, but thought I'd share :)
participants (10)
-
Andrew Barnert
-
Cameron Simpson
-
Carl Smith
-
Chris Angelico
-
David Mertz
-
Haoyi Li
-
João Bernardo
-
MRAB
-
Ryan Gonzalez
-
Steven D'Aprano