PEP-308 a "simplicity-first" alternative

Paul Paterson hamonlypaulpaterson at houston.rr.com
Thu Feb 13 01:35:26 EST 2003


"Erik Max Francis" <max at alcyone.com> wrote in message
news:3E4B220C.18EF1202 at alcyone.com...
> Paul Paterson wrote:
>
> > Using your definitions it's not ambiguous but it can be misleading
> > since, in
> > all other forms I recall seeing, C is the conditional test to select
> > the
> > normal or primary value. Hence a quick reading of "y or x if C" might
> > lead
> > you to believe that x is intended to be the normal result.
>
> It _is_ the normal result, if by "normal result" you mean "the
> expression that is to be evaluated if the condition evaluates to true."
> If you mean something else by "normal result," I don't understand why
> you're making a distinction that only serves to confuse matters more.

This is in fact the opposite of what I mean! Let me show by two examples.

val1 = sqrt(x) or "imag" if x < 0
val2 = lst[i] or default of i < 0

I am defining the "normal" results for val1 and val2 as sqrt(x) and lst[i].
These are the values which I, the author, intend to be normally returned. I
also catch the special cases which break my sqrt/lst and return something
else (the abnormal cases). The condition, when evaluated to true, selects
the abnormal case. The condition is not normally expected to evaluate to
true. (Yes, I realize there are also many cases where this normal/abnormal
distinction makes no sense).

Now compare,

val1 = sqrt(x) if x>=0 else "imag"
val2 = lst[i] if i>=0 else default

sqrt(x) and lst[i] are still the "normal" results but they are selected by
the condition.

It's a fairly important feature of my form that the condition selects the
abnormal value for reasons I mentioned in another post. Using the x, y, C
notation (and I understand why you have to do that) it is easy to miss this
distinction by assuming that you can simply replace the x, y and C from
other forms, eg:

PEP form: x if C else y
my form: y or x if C

This is what you get by replacing the terms...

PEP form:      sqrt(x) if x>=0 else "imag"
my form:        "imag" or sqrt(x) if x>=0

While correct, this is not the intended use of my form (which is shown
above).

I hope this is a bit clearer. Maybe not!

Paul
- Proposing a new conditional form is like trying to flog a dead horse to
water and then teach it new tricks






More information about the Python-list mailing list