[Python-ideas] Accessing the result of comprehension's expression from the conditional

Lie Ryan lie.1296 at gmail.com
Sat Jun 20 20:08:05 CEST 2009


Steven D'Aprano wrote:
>> The advantage of F being callable is that it does not need semantic
>> change, the filtering part will be done before expression just like
>> it is right now.
> 
> That's not true. It can't be true. If you want to filter on x**x being 
> greater than 100, you need to calculate x**x first. In theory, a 
> sufficiently clever compiler could recognise that, say, x**x < 100 
> implies 0 <= x < 3.59728 (approx), but in general, you can't predict 
> the value of f(x) without actually calculating f(x).

Did you read the middle part of the post and the diagram, which address
the question you're asking and how it would be handled?

> What happens if you accidentally forget to put brackets after the F 
> expression? Do you get a syntax error? Undefined behaviour? A runtime 
> exception?

As F is just callable, F > 100 should result in comparison of number
against callable. But as it is rare that you really actually wanted to
do such thing, I think python can also be a little protective and issue
a warning.




More information about the Python-ideas mailing list