[Python-ideas] Another way to avoid clumsy lambdas, while adding new functionality
Ryan Gonzalez
rymg19 at gmail.com
Wed Mar 5 00:57:31 CET 2014
Only problem is that it looks a tad perlish...
On Tue, Mar 4, 2014 at 5:09 PM, Carl Smith <carl.input at gmail.com> wrote:
> 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 :)
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
--
Ryan
If anybody ever asks me why I prefer C++ to C, my answer will be simple:
"It's becauseslejfp23(@#Q*(E*EIdc-SEGFAULT. Wait, I don't think that was
nul-terminated."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140304/e7c9b5d9/attachment-0001.html>
More information about the Python-ideas
mailing list