PEP-308 a "simplicity-first" alternative

Bengt Richter bokr at oz.net
Wed Feb 12 20:57:51 EST 2003


On Wed, 12 Feb 2003 17:09:32 -0700, "Bjorn Pettersen" <BPettersen at NAREX.com> wrote:

>> From: Bengt Richter [mailto:bokr at oz.net]=20
>[...]
>> I think I have an answer:
>>=20
>>     result =3D cond and {true_value} or false_value
>
>Yes, we got you the first three times <wink>. Your proposal
Sorry 'bout that, but I thought this tack was different from
all the others, since it just puts a truth-wrapper on an arbitrary
term for purposes of logical test. It doesn't otherwise alter any
syntax or introduce new forms etc.

Perhaps you saw it as yet another specialized ternary form. It is not.
{x} would be a valid expression anywhere, just guaranteeing that
bool({x}) == True, but being its normal value in any expression
that wasn't testing its logical value.

This happens to fix the hole in old ternary idiom, but it is _not_
introducing a new ternary form or other complex context-dependent stuff.
If 
    (x and [y] or [b])[0]

is understandable, why not the much simpler logical-true-wrapper in

    x and {y} or b

?
>
> 1. Doesn't give any indication that the expression is
>    a selection (i.e. the same as x and y or b).
b? I expected z ;-)

If you understand
    x and y or b

I would think
    x and {y} or b

would make you think {y} would be selected if true, whatever {y} meant.
If you had read the updated docs on logical expressions and short-circuit
evaluation, you would know. If you hadn't, you might post a question on c.l.p ;-)

> 2. Introduces random symbols that give simple expressions
>    new (and surprising) meaning... (i.e. just like Perl.)
Why do you call {} random? On the contrary, they are chosen
to be a minimal syntax change to define a wrapping operation
that happens make the old idiom work.

Regards,
Bengt Richter




More information about the Python-list mailing list