Re: function with variable arguments

2005-05-14 Thread Harald Schmidt
Xah Lee wrote: > I think it would be a improvement for the built-in range() so that step > needs not be an integer. [...] > > Range( 5, 7, 0.3); # returns [5, 5.3, 5.6, 5.9, 6.2, 6.5, 6.8] This may not return what you expect it to return. For example let's use a naive implementation like this:

Re: function with variable arguments

2005-05-14 Thread tiissa
Xah Lee wrote: > on a related topic, > I think it would be a improvement for the built-in range() so that step > needs not be an integer. There are easy workarounds but I'd find it useful as well. > Further, it'd be better to support decreasing range. e.g. > > Range( 5, 7, 0.3); # returns [5, 5.

Re: function with variable arguments

2005-05-14 Thread Xah Lee
Thanks to all for the reply. (i should've known better) on a related topic, I think it would be a improvement for the built-in range() so that step needs not be an integer. Further, it'd be better to support decreasing range. e.g. Range( 5, 7, 0.3); # returns [5, 5.3, 5.6, 5.9, 6.2, 6.5, 6.8] Ran

Re: function with variable arguments

2005-05-13 Thread Wolfram Kriesing
> def Range(n,m=None,step=1): > if m is None: > n,m = 0,n+1 > else: > n,m = n,m+1 > return range(n,m,step) i like this one. coming from php (just a couple weeks ago) its always again interesting to see how i have to start thinking to program differently, it can be so much easier wi

Re: function with variable arguments

2005-05-13 Thread PoD
On Fri, 13 May 2005 02:52:34 -0700, Xah Lee wrote: > i wanted to define a function where the number of argument matters. > Example: > > def Range(n): > return range(n+1) > > def Range(n,m): > return range(n,m+1) > > def Range(n,m,step): > return range(n,m+1,step) > > this obvious d

Re: function with variable arguments

2005-05-13 Thread Peter Dembinski
On Fri, 13 May 2005 11:52:34 +0200, Xah Lee <[EMAIL PROTECTED]> wrote: > i wanted to define a function where the number of argument matters. > Example: > > def Range(n): > return range(n+1) > > def Range(n,m): > return range(n,m+1) > > def Range(n,m,step): > return range(n,m+1,step) >

Re: function with variable arguments

2005-05-13 Thread Dan Sommers
On 13 May 2005 02:52:34 -0700, "Xah Lee" <[EMAIL PROTECTED]> wrote: > i wanted to define a function where the number of argument matters. > Example: > def Range(n): > return range(n+1) > def Range(n,m): > return range(n,m+1) > def Range(n,m,step): > return range(n,m+1,step) > this

Re: function with variable arguments

2005-05-13 Thread Steve
On 5/13/05, Wolfram Kriesing <[EMAIL PROTECTED]> wrote: > using default args does actually solve it > what about > def Range(n, m=None, step=None) > if step==None: > if m==None: > range(n) > else: <...snip...> or better still : def Range(*args): return range(*args) Regards

Re: function with variable arguments

2005-05-13 Thread Wolfram Kriesing
using default args does actually solve it what about def Range(n, m=None, step=None) if step==None: if m==None: range(n) else: range(n,m) else: if m==None: raise Exception, "missing parameter m" else: range(n,m,step) can be optimized i am sure :-) --

function with variable arguments

2005-05-13 Thread Xah Lee
i wanted to define a function where the number of argument matters. Example: def Range(n): return range(n+1) def Range(n,m): return range(n,m+1) def Range(n,m,step): return range(n,m+1,step) this obvious doesn't work. The default argument like Range(n=1,m,step=1) obviously isn't a s