One other possibilty for PEP 308...

Rich Harkins rich at worldsinfinite.com
Sun Feb 9 16:04:02 EST 2003


Here's one other way to go.  It's going to sound weird but I figure I
might as run it up the flagpole while we're all talking about trinary
if-then-else operations.  

I suggest creating a new singleton called "Default" or some such which
has the following properties:

1) When used as the left-hand side of a logical "and", the right hand
side is not evaluated and the result is Default.
2) When used as the left-hand side of a logical "or", the right hand
side is evaluated and the result is returned.
3) When used as a function if the argument passed is non-zero (True)
then return the argument otherwise return the Default object.
4) (And this is the REAL problem with my proposal here) Overload the
keyword "else" (default OR) to act exactly as traditional "or" except
that it will ONLY execute the right hand side if the left hand side is
Default (thus eliminating the false-left-side case).

For example:

Default(condition) and truecase else falsecase

By doing this truecase could produce any value and the falsecase is
never executed.  In addition, truecase COULD produce Default indicating
that it the falsecase value is acceptible to the truecase after all.  In
addition, the following semantic can be issued:

x=Default		# We don't care
print "x is",x else 5	# 5 because x is Default.
x=0
print "x is now",x else 5 # 0 because x is not Default

Obviously, the spellings would have to change as appropriate but you get
the idea.

To sum up, why couldn't we create an entity such that it yields to any
other entity when manipulated?

Just some thoughts on the matter
Rich

BTW: As I've said elsewhere I do like the PEP as it stands too...







More information about the Python-list mailing list