On Mon, Aug 21, 2017 at 8:39 AM, alister via Python-list
wrote:
> On Mon, 21 Aug 2017 05:44:53 -0700, jek wrote:
>> This is a very old post, but since I just though I would like a
>> conditional return like this, and checked for previous proposals, I
>> thought I'd give my
On Mon, 21 Aug 2017 05:44:53 -0700, jek wrote:
> This is a very old post, but since I just though I would like a
> conditional return like this, and checked for previous proposals, I
> thought I'd give my opinion.
>
> Unfortunately only about 8 of the 67 replies actually answer the
> question,
This is a very old post, but since I just though I would like a conditional
return like this, and checked for previous proposals, I thought I'd give my
opinion.
Unfortunately only about 8 of the 67 replies actually answer the question, and
there isn't any overwhelming consensus to if a
Am 13.04.2011 01:06, schrieb Ethan Furman:
-- def func():
-- var1 = something()
-- var2 = something_else('this')
-- return? var1.hobgle(var2)
-- var3 = last_resort(var1)
-- return var3.wiglat(var2)
This makes me think of a decorator which can mimic the wantend behaviour:
def getfirst(f):
Gregory Ewing writes:
Chris Angelico wrote:
Question: How many factorial functions are implemented because a
program needs to know what n! is, and how many are implemented to
demonstrate recursion (or to demonstrate the difference between
iteration and recursion)? :)
(I can't get to
On Tue, Apr 19, 2011 at 4:42 PM, Jussi Piitulainen
jpiit...@ling.helsinki.fi wrote:
Factorials become an interesting demonstration of recursion when done
well. There's a paper by Richard J. Fateman, citing Peter Luschny:
http://www.cs.berkeley.edu/~fateman/papers/factorial.pdf
In article mailman.461.1303043638.9059.python-l...@python.org,
D'Arcy J.M. Cain da...@druid.net wrote:
On Sun, 17 Apr 2011 16:21:53 +1200
Gregory Ewing greg.ew...@canterbury.ac.nz wrote:
My idiom for fetching from a cache looks like this:
def get_from_cache(x):
y = cache.get(x)
Chris Angelico wrote:
Question: How many factorial functions are implemented because a
program needs to know what n! is, and how many are implemented to
demonstrate recursion (or to demonstrate the difference between
iteration and recursion)? :)
A related question is how often factorial
On Sun, 17 Apr 2011 16:21:53 +1200, Gregory Ewing wrote:
Chris Angelico wrote:
def fac(n):
# attempt to get from a cache
return? cache[n]
# not in cache, calculate the value
ret=1 if n=1 else fac(n-1)*n
# and cache and return it
cache[n]=ret; return ret
My
On Sun, Apr 17, 2011 at 6:45 PM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
On Sun, 17 Apr 2011 16:21:53 +1200, Gregory Ewing wrote:
Chris Angelico wrote:
def fac(n):
# attempt to get from a cache
return? cache[n]
# not in cache, calculate the value
ret=1
be expanded to
_temp = expr
if _temp: return _temp
This could be simplified to just:
return expr or None
No, it can't be simplified in this way.
If there is code after that snippet, then
it will get executed in the original version if _temp is
false, but won't get executed in
On Sun, 17 Apr 2011 16:21:53 +1200
Gregory Ewing greg.ew...@canterbury.ac.nz wrote:
My idiom for fetching from a cache looks like this:
def get_from_cache(x):
y = cache.get(x)
if not y:
y = compute_from(x)
cache[x] = y
return y
I prefer not to create and
On Sun, 17 Apr 2011 08:33:47 -0400, D'Arcy J.M. Cain wrote:
On Sun, 17 Apr 2011 16:21:53 +1200
Gregory Ewing greg.ew...@canterbury.ac.nz wrote:
My idiom for fetching from a cache looks like this:
def get_from_cache(x):
y = cache.get(x)
if not y:
y = compute_from(x)
On Sun, 17 Apr 2011 19:07:03 +1000, Chris Angelico wrote:
If there's the
possibility of _ANY_ value coming back from the computation, then it
would need to be done as:
if x in cache: return cache[x]
Or you can create a sentinel value that is guaranteed to never appear
anywhere else:
D'Arcy J.M. Cain wrote:
On Sun, 17 Apr 2011 16:21:53 +1200
Gregory Ewing greg.ew...@canterbury.ac.nz wrote:
def get_from_cache(x):
y = cache.get(x)
if not y:
y = compute_from(x)
cache[x] = y
return y
I prefer not to create and destroy objects needlessly.
How does
On Sun, Apr 17, 2011 at 8:03 PM, Martin v. Loewis mar...@v.loewis.de wrote:
No, it can't be simplified in this way.
If there is code after that snippet, then
it will get executed in the original version if _temp is
false, but won't get executed in your simplification.
Martin, we've been over
Steven D'Aprano wrote:
I'm sure you realise that that snippet needlessly recalculates any cached
result that happens to be false, but others reading might not.
I only use it as written when I'm dealing with types that
don't have false values. If I did need to cache such a
type, I would use a
On 01/-10/-28163 02:59 PM, Chris Angelico wrote:
snip
Sure. In my (somewhat contrived) example of factorials, that's going
to be true (apart from 0! = 0); and if the function returns a string
or other object rather than an integer, same thing. If there's the
Just to be pedantic, by any
On Mon, Apr 18, 2011 at 12:04 PM, Dave Angel da...@ieee.org wrote:
On 01/-10/-28163 02:59 PM, Chris Angelico wrote:
snip
Sure. In my (somewhat contrived) example of factorials, that's going
to be true (apart from 0! = 0); and if the function returns a string
or other object rather than an
Chris Angelico wrote:
def fac(n):
# attempt to get from a cache
return? cache[n]
# not in cache, calculate the value
ret=1 if n=1 else fac(n-1)*n
# and cache and return it
cache[n]=ret; return ret
My idiom for fetching from a cache looks like this:
def
On Sun, Apr 17, 2011 at 2:21 PM, Gregory Ewing
greg.ew...@canterbury.ac.nz wrote:
My idiom for fetching from a cache looks like this:
def get_from_cache(x):
y = cache.get(x)
if not y:
y = compute_from(x)
cache[x] = y
return y
which doesn't require any conditional
* 2011-04-12T13:26:48-07:00 * Chris Rebert wrote:
I think Ben Yahtzee Croshaw's comments on open-world sandbox video
games (of all things) have a lot of applicability to why allowing
full-on macros can be a bad idea.
IOW, a language is usually better for having such discussions and
having a
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
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
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.
--
On Tue, 12 Apr 2011 16:21:43 +1000, James Mills 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.
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 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
On 2011-04-12, James Mills prolo...@shortcircuit.net.au wrote:
On Tue, Apr 12, 2011 at 12:18 PM, Grant Edwards invalid@invalid.invalid
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?
On 2011-04-12, James Mills prolo...@shortcircuit.net.au wrote:
On Tue, Apr 12, 2011 at 12:44 PM, Chris Angelico ros...@gmail.com 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
On 2011-04-12, 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.
On 12-Apr-11 06:55 AM, scattered wrote:
On Apr 12, 2:21 am, James Millsprolo...@shortcircuit.net.au wrote:
On Tue, Apr 12, 2011 at 4:08 PM, Nobodynob...@nowhere.com wrote:
It should be abundantly clear that this only returns if the expression is
considered true, otherwise it continues on to
On Tue, 2011-04-12 at 12:44 +1000, Chris Angelico wrote:
On Tue, Apr 12, 2011 at 12:20 PM, James Mills
prolo...@shortcircuit.net.au wrote:
On Tue, Apr 12, 2011 at 12:18 PM, Jason Swails jason.swa...@gmail.com
wrote:
This is only true if n 5. Otherwise, the first returns None and the
On Apr 12, 10:05 am, Westley Martínez aniko...@gmail.com wrote:
On Tue, 2011-04-12 at 12:44 +1000, Chris Angelico wrote:
On Tue, Apr 12, 2011 at 12:20 PM, James Mills
prolo...@shortcircuit.net.au wrote:
On Tue, Apr 12, 2011 at 12:18 PM, Jason Swails jason.swa...@gmail.com
wrote:
Paul Rubin 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
* 2011-04-12T10:27:55+10:00 * James Mills wrote:
On Tue, Apr 12, 2011 at 9:17 AM, zildjohn01 zildjoh...@gmail.com wrote:
This is an idea I've had bouncing around in my head for a long time
now. I propose the following syntax:
Maybe this is more appropriare for the python-ideas list ?
On Tue, Apr 12, 2011 at 12:00 PM, Teemu Likonen tliko...@iki.fi wrote:
I'm a simple Lisp guy who wonders if it is be possible to add some kind
of macros to the language. Then features like this could be added by
anybody. Lisp people do this all the time and there is no need for
feature
Wow. Two dozen replies, the majority of which are arguing over whether
the end of my snippet is reachable. I thought the behavior of if
statements was well-established by this point.
Regardless of James Mills's coding prowess, I suppose I should follow
his advice and repost this to the
On Tue, Apr 12, 2011 at 12:25 PM, Ian Kelly ian.g.ke...@gmail.com wrote:
On Tue, Apr 12, 2011 at 12:00 PM, Teemu Likonen tliko...@iki.fi wrote:
I'm a simple Lisp guy who wonders if it is be possible to add some kind
of macros to the language. Then features like this could be added by
anybody.
Teemu Likonen tliko...@iki.fi writes:
I'm a simple Lisp guy who wonders if it is be possible to add some kind
of macros to the language...
As a (now somewhat lapsed) long-time lisp programmer I sympathise with
the sentiment, but suspect that it's not going to gain serious traction
in python
On 4/12/2011 2:25 PM, zildjohn01 wrote:
Wow. Two dozen replies, the majority of which are arguing over whether
the end of my snippet is reachable. I thought the behavior of if
statements was well-established by this point.
Regardless of James Mills's coding prowess, I suppose I should follow
On 2011-04-12, Ian Kelly ian.g.ke...@gmail.com wrote:
Flow-control macros were suggested as part of PEP 343, but they
were rejected by Guido based on this rant:
http://blogs.msdn.com/b/oldnewthing/archive/2005/01/06/347666.aspx
Flow control macros don't seem to create problems that exceptions
On 2011-04-12, Neil Cerutti ne...@norwich.edu wrote:
On 2011-04-12, Ian Kelly ian.g.ke...@gmail.com wrote:
Flow-control macros were suggested as part of PEP 343, but
they were rejected by Guido based on this rant:
http://blogs.msdn.com/b/oldnewthing/archive/2005/01/06/347666.aspx
Flow
On Tue, Apr 12, 2011 at 11:00 AM, Teemu Likonen tliko...@iki.fi wrote:
* 2011-04-12T10:27:55+10:00 * James Mills wrote:
On Tue, Apr 12, 2011 at 9:17 AM, zildjohn01 zildjoh...@gmail.com wrote:
This is an idea I've had bouncing around in my head for a long time
now. I propose the following
On Wed, Apr 13, 2011 at 6:26 AM, Chris Rebert c...@rebertia.com wrote:
Paraphrasing liberally from his review of Far Cry 2:
Letting the [programmer] create their own [language constructs is]
always done at the expense of proper [orthogonality, elegance, and
coherence]. Maybe sometimes I don't
On Tue, 2011-04-12 at 07:58 -0700, scattered wrote:
On Apr 12, 10:05 am, Westley Martínez aniko...@gmail.com wrote:
On Tue, 2011-04-12 at 12:44 +1000, Chris Angelico wrote:
On Tue, Apr 12, 2011 at 12:20 PM, James Mills
prolo...@shortcircuit.net.au wrote:
On Tue, Apr 12, 2011 at 12:18
On Wed, Apr 13, 2011 at 8:45 AM, Westley Martínez aniko...@gmail.com wrote:
I don't think that this is equivalent. The OP's original idea doesn't
involve a loop, but this does - how could that be equivalent?
Not OP's idea, Angelico's.
I didn't actually advocate a loop, but that method could
James Mills wrote:
Are we done with this discussion yet ? :)
*sigh* It was a slow day yesterday and I have
a funny feeling it's going to be the same today!
Regardless of anyone's subjective opinions as to what
was clear - I still stand by what I said.
I think I see your point -- the OP said:
On Wed, Apr 13, 2011 at 9:06 AM, Ethan Furman et...@stoneleaf.us wrote:
I think I see your point -- the OP said:
-- _temp = expr
-- if _temp: return _temp
which is where you're getting
-- return _temp or None
However, most everyone ('cept you, it seems! ;) understood that there
On Tue, 2011-04-12 at 16:06 -0700, Ethan Furman wrote:
James Mills wrote:
Are we done with this discussion yet ? :)
*sigh* It was a slow day yesterday and I have
a funny feeling it's going to be the same today!
Regardless of anyone's subjective opinions as to what
was clear - I still
Westley Martínez wrote:
On Tue, 2011-04-12 at 16:06 -0700, Ethan Furman wrote:
-- def func():
-- var1 = something()
-- var2 = something_else('this')
-- return? var1.hobgle(var2)
-- var3 = last_resort(var1)
-- return var3.wiglat(var2)
The question mark makes the programmer
On Tue, 12 Apr 2011 16:48:31 -0700, Ethan Furman wrote:
Westley Martínez wrote:
On Tue, 2011-04-12 at 16:06 -0700, Ethan Furman wrote:
-- def func():
-- var1 = something()
-- var2 = something_else('this') -- return?
var1.hobgle(var2)
-- var3 = last_resort(var1)
--
Steven D'Aprano wrote:
On Tue, 12 Apr 2011 16:48:31 -0700, Ethan Furman wrote:
Westley Martínez wrote:
On Tue, 2011-04-12 at 16:06 -0700, Ethan Furman wrote:
-- def func():
-- var1 = something()
-- var2 = something_else('this') -- return?
var1.hobgle(var2)
-- var3 =
On Wed, Apr 13, 2011 at 12:42 PM, Ethan Furman et...@stoneleaf.us wrote:
The indentation for return and raise is the next coded line. List comps and
gen exps are basically uber-functions, and regardless of how you categorize
them when they finish it is easy to see where control goes to next
On Wed, Apr 13, 2011 at 1:00 PM, Chris Angelico ros...@gmail.com wrote:
def foo(param):
resource=malloc(5) # Shtarker, zis is Python! We don't malloc here!
if not resource: return 0
resource[param]=5
del resource
return 1
In Python this can probably be done and perhaps is
zildjohn01 zildjoh...@gmail.com wrote:
Regardless of James Mills's coding prowess[...]
James is the sole dev of a very handy elegant event framework:
https://bitbucket.org/prologic/circuits/ Can you point out any
equivalent achievements so we can compare?
And make sure to carry that attitude
This is an idea I've had bouncing around in my head for a long time
now. I propose the following syntax:
return? expr
be expanded to
_temp = expr
if _temp: return _temp
It's a pattern I use all the time in my code, and although it's a bit
unorthodox, IMO it's concise, readable, and
On Tue, Apr 12, 2011 at 9:17 AM, zildjohn01 zildjoh...@gmail.com wrote:
This is an idea I've had bouncing around in my head for a long time
now. I propose the following syntax:
Maybe this is more appropriare for the python-ideas list ?
return? expr
This syntax does not fit well within
On Tue, Apr 12, 2011 at 10:27 AM, James Mills
prolo...@shortcircuit.net.au wrote:
This could be simplified to just:
return expr or None
And more to the point... If your calee is relying
on the result of this function, just returning the
evaluation of expr is enough.
I'm thinking here that
On Tue, Apr 12, 2011 at 10:46 AM, Chris Angelico ros...@gmail.com wrote:
def fac(n):
return cache[n] or (cache[n]=1 if n=1 else fac(n-1)*n)
Hmm. The function-call version of dictionary assignment IS legal in an
expression, but it's getting stupid...
def fac(n):
return cache.get(n) or
On 2011-04-12, James Mills prolo...@shortcircuit.net.au wrote:
On Tue, Apr 12, 2011 at 9:17 AM, zildjohn01 zildjoh...@gmail.com wrote:
This is an idea I've had bouncing around in my head for a long time
now. I propose the following syntax:
Maybe this is more appropriare for the python-ideas
On Tue, Apr 12, 2011 at 11:44 AM, Grant Edwards invalid@invalid.invalid wrote:
How is that the same?
return? something() return something() or None
return? somethingelse() return somethingelse() or None
log(didn't find an answer) log(didn't find an
On Mon, Apr 11, 2011 at 7:12 PM, James Mills
prolo...@shortcircuit.net.auwrote:
Are you saying the two snippets above are equivalent?
def foo(n):
x = n 5
if x:
return x
is functionally equivalent to:
def foo(n):
return n 5
This is only true if n 5. Otherwise,
On 2011-04-12, James Mills prolo...@shortcircuit.net.au wrote:
On Tue, Apr 12, 2011 at 11:44 AM, Grant Edwards invalid@invalid.invalid
wrote:
How is that the same?
??return? something() ?? ?? ?? ?? ?? ?? ?? ?? ??return something() or None
??return? somethingelse() ?? ?? ?? ?? ?? ?? ??return
On Tue, Apr 12, 2011 at 12:18 PM, Jason Swails jason.swa...@gmail.com wrote:
This is only true if n 5. Otherwise, the first returns None and the
second returns False.
Which is why I said:
return expr or None
But hey let's argue the point to death!
cheers
James
--
-- James Mills
--
--
:
This is only true if n 5. Otherwise, the first returns None and the
second returns False.
Which is why I said:
return expr or None
But hey let's argue the point to death!
Ok ;-)
I think the point is that OP doesn't want to return *at all* if expr
is False - presumably because there
On Tue, Apr 12, 2011 at 12:20 PM, James Mills
prolo...@shortcircuit.net.au wrote:
On Tue, Apr 12, 2011 at 12:18 PM, Jason Swails jason.swa...@gmail.com wrote:
This is only true if n 5. Otherwise, the first returns None and the
second returns False.
Which is why I said:
return expr or None
On Tue, Apr 12, 2011 at 12:18 PM, Grant Edwards invalid@invalid.invalid 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
On Tue, Apr 12, 2011 at 12:43 PM, Zero Piraeus sche...@gmail.com 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
On Tue, Apr 12, 2011 at 12:43 PM, Zero Piraeus sche...@gmail.com 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
On Tue, Apr 12, 2011 at 12:44 PM, Chris Angelico ros...@gmail.com 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
71 matches
Mail list logo