On Aug 27, 2008, at 12:14 AM, Chris Monson wrote:
Now thinking as a language designer, C# has a ?? operator where A??B is shorthand for (B if A is None else A) except you only have to write A once and A is only evaluated once. A Pythonesque version of this would be just "else":

   def foo(arg=None, arg2=None):
      arg = arg else bar
      arg2 = arg2 else list()

And I think that metaphor is easy to read. Chains of else operators can be useful:

   x = f() else g() else h() else 0

Not a bad idea.  Looks like the time machine is at work again:

x = f() or g() or h() or 0

Well...no. "else" here is significantly different from "or": it only tests for None, not falseness.

>>> A = 0
>>> B = 1

>>> B if A is None else A # suggested equivalence for "A else B"
0
>>> A or B
1

Although, maybe you just meant that "else" and "or" have such similar behavior, and their names do not obviously distinguish their behavior. And, thus, people would find them confusing, so "else" should not be added to the language. That I could agree with.

James
_______________________________________________
Python-3000 mailing list
Python-3000@python.org
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

Reply via email to