For review: PEP 308 - If-then-else expression
Roman Suzi
rnd at onego.ru
Sun Feb 9 13:30:54 EST 2003
On 8 Feb 2003, Paul Rubin wrote:
>How about further abuse of colon:
>
> f(:expression)
>
>is short for f(lambda: expression)
>
>So we'd implement a conditional expression with
>
> def cond(condition, v1, v2):
> if condition:
> return v1()
> else:
> return v2()
>
>To call it, we'd say, for example,
>
> print cond(x >= 0, :sqrt(x), :"imaginary roots")
Better to make ! equal to lambda ;-)
print cond(x >= 0, !:sqrt(x), !:"imaginary roots")
>I don't see immediately whether this makes any syntax ambiguities with
>existing statements, since I can't think of anyplace where colon can
>currently appear where an expression can also appear.
>
Sincerely yours, Roman Suzi
--
rnd at onego.ru =\= My AI powered by Linux RedHat 7.3
More information about the Python-list
mailing list