Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Feature suggestion -- return if true

Reply
Thread Tools

Feature suggestion -- return if true

 
 
James Mills
Guest
Posts: n/a
 
      04-12-2011
On Tue, Apr 12, 2011 at 12:18 PM, Grant Edwards <> wrote:
> You stated that
>
> Â*return? <expr>
>
> was equivalent to
>
> Â*return <expr> or None


This is _not_ what I said.

Quoting from my earlier post:

"""
> return? expr


This syntax does not fit well within python ideology.

> be expanded to
>
> _temp = expr
> if _temp: return _temp


This could be simplified to just:

return expr or None
"""

Please read carefully before putting words in my mouth.

I stated very clear y that return? expr didn't seem fitting
in the python ideology as syntax for this behavior.

cheers
James

--
-- James Mills
--
-- "Problems are solved by method"
 
Reply With Quote
 
 
 
 
Chris Angelico
Guest
Posts: n/a
 
      04-12-2011
On Tue, Apr 12, 2011 at 12:43 PM, Zero Piraeus <> wrote:
> *return? expr
>
> isn't very pythonic - so how about one of these?
>
> *return expr if True
> *return expr else continue
>
> I kid, I kid ...


Or:

if expr:
return it

Actually, I'm not sure how stupid an idea that is. Inside an if, 'it'
is the value of the condition. Might actually be useful in a few
places.... Naw, I think it's still a stupid idea.

Chris Angelico
 
Reply With Quote
 
 
 
 
James Mills
Guest
Posts: n/a
 
      04-12-2011
On Tue, Apr 12, 2011 at 12:43 PM, Zero Piraeus <> wrote:
> I think the point is that OP doesn't want to return *at all* if expr
> is False - presumably because there are further statements after the
> proposed 'conditional' return.


If that's the case then we're all making assumptions
about what the OP intended. Perhaps OPs should be more
clear ?

kid!

cheers
James

--
-- James Mills
--
-- "Problems are solved by method"
 
Reply With Quote
 
James Mills
Guest
Posts: n/a
 
      04-12-2011
On Tue, Apr 12, 2011 at 12:44 PM, Chris Angelico <> wrote:
> That's still not equivalent. "return expr or None" will always
> terminate the function. The OP's request was for something which would
> terminate the function if and only if expr is non-false.


The OP did not state this at all.
There was never any mention of early termination
of the function iif expr was True.

Sorry :/ I'm not picking on your comprehension skills here
but you didn't read what the OP wrote (which he/she may not have
been clear about in the first place( nor what I said in reply.

Have a nice day,

cheers
James

--
-- James Mills
--
-- "Problems are solved by method"
 
Reply With Quote
 
Nobody
Guest
Posts: n/a
 
      04-12-2011
On Tue, 12 Apr 2011 13:01:43 +1000, James Mills wrote:

>> That's still not equivalent. "return expr or None" will always
>> terminate the function. The OP's request was for something which would
>> terminate the function if and only if expr is non-false.

>
> The OP did not state this at all.
> There was never any mention of early termination
> of the function iif expr was True.


What the OP actually said was:

> I propose the following syntax:
>
> return? expr
>
> be expanded to
>
> _temp = expr
> if _temp: return _temp


It should be abundantly clear that this only returns if the expression is
considered true, otherwise it continues on to the following statements.


 
Reply With Quote
 
James Mills
Guest
Posts: n/a
 
      04-12-2011
On Tue, Apr 12, 2011 at 4:08 PM, Nobody <> wrote:
> It should be abundantly clear that this only returns if the expression is
> considered true, otherwise it continues on to the following statements.


Uggh come on guys. We've been over this.
You cannot make that assumption.

cheers
James


--
-- James Mills
--
-- "Problems are solved by method"
 
Reply With Quote
 
Paul Rubin
Guest
Posts: n/a
 
      04-12-2011
zildjohn01 <> writes:
> _temp = expr
> if _temp: return _temp


I'm trying to figure out a context where you'd even want that, and I'm
thinking that maybe it's some version of a repeat-until loop? Python
doesn't have repeat-until and it's been proposed a few times.
 
Reply With Quote
 
Steven D'Aprano
Guest
Posts: n/a
 
      04-12-2011
On Tue, 12 Apr 2011 16:21:43 +1000, James Mills wrote:

> On Tue, Apr 12, 2011 at 4:08 PM, Nobody <> wrote:
>> It should be abundantly clear that this only returns if the expression
>> is considered true, otherwise it continues on to the following
>> statements.

>
> Uggh come on guys. We've been over this. You cannot make that
> assumption.


The code snippet is absolutely clear. It is ordinary Python code:

_temp = expr
if _temp: return _temp

You should notice the lack of "else: return None" in that code snippet.

The only assumption being made is that the OP means what he says.

I suppose you can assume that he means something else if you like, but
then you have no possible way of knowing what he actually means ("well, I
*said* conditional return, but I *meant* BEGIN and END delimiters like in
Pascal...").

Personally, I like the idea of a conditional return, but I *hate* the
proposed syntax. But I don't think it's useful enough to deserve a new
keyword either.



--
Steven
 
Reply With Quote
 
scattered
Guest
Posts: n/a
 
      04-12-2011
On Apr 12, 2:21*am, James Mills <prolo...@shortcircuit.net.au> wrote:
> On Tue, Apr 12, 2011 at 4:08 PM, Nobody <nob...@nowhere.com> wrote:
> > It should be abundantly clear that this only returns if the expression is
> > considered true, otherwise it continues on to the following statements.

>
> Uggh come on guys. We've been over this.
> You cannot make that assumption.
>
> cheers
> James
>
> --
> -- James Mills
> --
> -- "Problems are solved by method"


I'm puzzled as to why you seem to be parsing the OP's statements
different from everybody else. The only assumption that people other
than you seem to be making is that they are assuming that the OP meant
what he said. He *gave* a definition of what he meant by return? and
the definition he actually gave has the property that it terminates
the function only when the condition is true, whereas your suggested
translation *always* terminates the function call. I agree with
"Nobody" that the OP's intention was "abundantly clear". Your "return
expr or None" suggestion was not an unreasonable try - but it doesn't
provide something which is equivalent to what the OP gave. On the
other hand, your persistence in defending your original statement as a
plausible translation of return? after the difference has been pointed
out by various posters *is* starting to become unreasonable.
 
Reply With Quote
 
John Roth
Guest
Posts: n/a
 
      04-12-2011
On Apr 12, 12:58*am, Paul Rubin <no.em...@nospam.invalid> wrote:
> zildjohn01 <zildjoh...@gmail.com> writes:
> > * * _temp = expr
> > * * if _temp: return _temp

>
> I'm trying to figure out a context where you'd even want that, and I'm
> thinking that maybe it's some version of a repeat-until loop? *Python
> doesn't have repeat-until and it's been proposed a few times.


I've wanted that a few times, frequently in a situation where I'm
doing validity checking, and I either want to continue after calling a
validity check or return immediately with some kind of error object.
For example:

returnif self.isitaboojum(snark)

This works nicely if the checking routine either returns False or an
error object.

It also works if the method is doing some kind of a ladder evaluation
of several distinct conditions, and it wants to return the first one
it finds.

Also, I wouldn't want a returnif in a loop. Following on with this
idea, loop control would be more of a breakif or continueif statement.

John Roth
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[False,True] and [True,True] --> [True, True]????? bdb112 Python 45 04-29-2009 02:35 AM
Suggestion for an "imagemap-like" location feature -- methods? KatB ASP .Net 4 01-22-2005 01:46 AM
feature suggestion flexibal Python 3 12-24-2004 11:36 PM
Does true ^ true return false? Siemel Naran C++ 19 06-18-2004 11:06 AM
difference between return true; and return false; w i l l Javascript 4 07-04-2003 10:05 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57