PEP-308 a "simplicity-first" alternative

Bengt Richter bokr at oz.net
Thu Feb 13 21:03:29 EST 2003


On Thu, 13 Feb 2003 19:19:18 +1300, Paul Foley <see at below.invalid> wrote:

>On 13 Feb 2003 04:05:01 GMT, Bengt Richter wrote:
>
>>     x and {y} or {z}
>
>So
>
>  x = 0
>  if {x}:
>     print "Hello, World"
>
>prints the message, right?  How about
Right.
>
>  x = 0
>  y = {x}
The above binds y to the value, distinguishing logical from non-logical
values something like
   y = 1 and x
does.

>  if y:
>     print "Hello, World"
>
>?  So what's the value of y now?  It's got to be 0 if you want the
>
>  x and {y} or {z}
>
>thing to do the right thing (i.e., if x is true, it's supposed to
Right.
>return the value of y, even if that corresponds to boolean false), so
>now you have two different zeros, one of which is logically false and
>the other is logically true.  And it returns the wrong one:
>
>  1 and (x and {y} or {z}) and "true"
>
>should be "true" if x is true and y is false...
No. It should be y. The above is
    1 and expr and "true"

where expr is
    (x and {y} or {z})

which has the same effect as 
    (x and [y] or [z])[0]

I.e., the truth-wrapper is peeled off when you evaluate the
expression, sort of like (quote x), so if x is "true" and y is false,
expr is
    ("true" and {y} or {z})

which evaluates to y (without {}), so we have
    1 and y and "true"

whose value is the terminating false _value_ of y,
(which could be None, '', [], (), etc).

>
>Bleargh!
Yeah, but there _is_ a method to the madness ;-)
OTOH, I do see the need for something easier to understand.
I just enjoy exploring the edges of a problem (up to a point ;-)

>
>
>I've got it!  (if x then: y else: z) with required parentheses is on
>the table -- how about answering the question of whether or not there
>should be colons in there by just dropping "then:" and "else:" and
>writing simply (if x y z)?  :-))
>
I had that thought too, and as your smiley may have presaged,
there's too many ambiguities (as Erik was quick to point out).

Your [c1->v1; c2->v2; ... True->vDefault] is looking better and better ;-)
(I may seem fickle, but my allegiance is to the pursuit of ideals, not
particular approximations along the way, so I try not to get too attached
to my own stuff, even in the midst of championing it ;-)

Regards,
Bengt Richter




More information about the Python-list mailing list