| Store | Cart

[Python-Dev] (try-except) conditional expression similar to (if-else) conditional (PEP 308)

From: MRAB <pyt...@mrabarnett.plus.com>
Fri, 07 Aug 2009 01:36:34 +0100
Russell E. Owen wrote:
> In article <D28975E8-6706-4515-9C9E-FB7F90775CA5 at masklinn.net>,>  Xavier Morel <catch-all at masklinn.net> wrote:> >> On 6 Aug 2009, at 00:22 , Jeff McAninch wrote:>>> I'm new to this list, so please excuse me if this topic has been  >>> discussed, but I didn't>>> see anything similar in the archives.>>>>>> I very often want something like a try-except conditional expression  >>> similar>>> to the if-else conditional.>> I fear this idea is soon going to extend to all compound statements  >> one by one.>>>> Wouldn't it be smarter to fix the issue once and for all by looking  >> into making Python's compound statements (or even all statements  >> without restrictions) expressions that can return values in the first  >> place? Now I don't know if it's actually possible, but if it is the  >> problem becomes solved not just for try:except: (and twice so for  >> if:else:) but also for while:, for: (though that one's already served  >> pretty well by comprehensions) and with:.> > I like this idea a lot.> 
For some reason this kind of reminds me of BCPL.

A function definition looked like:

     LET func_name(arg1, arg2) = expression

so, strictly speaking, no multiline functions.

However, there was also the VALOF ... RESULTIS ... block.

In Python, the 'return' statement provides the result of a function; in
BCPL, the 'RESULTIS' statement provided the result of the VALOF block,
which was call from within an expression, like:

     LET foo(...) = VALOF
     $(
         ...
         RESULTIS expression
     $)

Recent Messages in this Thread
Jeff McAninch Aug 05, 2009 10:22 pm
Raymond Hettinger Aug 06, 2009 12:59 am
P.J. Eby Aug 06, 2009 01:20 am
Nick Coghlan Aug 06, 2009 10:47 am
Dj Gilcrease Aug 06, 2009 11:18 am
MRAB Aug 06, 2009 11:39 am
Jeff McAninch Aug 06, 2009 02:36 pm
Dino Viehland Aug 06, 2009 09:55 pm
MRAB Aug 06, 2009 11:33 pm
Dino Viehland Aug 07, 2009 12:01 am
MRAB Aug 07, 2009 12:22 am
Jeff McAninch Aug 07, 2009 10:14 am
MRAB Aug 07, 2009 11:03 am
Dj Gilcrease Aug 10, 2009 02:29 pm
Jeff McAninch Aug 06, 2009 02:11 am
Antoine Pitrou Aug 06, 2009 11:32 am
Xavier Morel Aug 06, 2009 10:25 am
Russell E. Owen Aug 06, 2009 07:55 pm
MRAB Aug 07, 2009 12:36 am
Kristján Valur Jónsson Aug 07, 2009 10:22 am
ilya Aug 07, 2009 11:06 am
Michael Foord Aug 07, 2009 11:22 am
Alex Martelli Aug 07, 2009 02:55 pm
Steven DAprano Aug 08, 2009 06:02 am
Xavier Morel Aug 08, 2009 08:17 am
Stephen J. Turnbull Aug 08, 2009 01:19 pm
Alexander Kozlovsky Aug 14, 2009 10:41 pm
Steven DAprano Aug 10, 2009 11:45 pm
Messages in this thread