Re: language design question

2006-07-11 Thread Bryan
Fredrik Lundh wrote: > "Bryan" wrote: > >>> and how do you make sure that everything subclasses this base class ? >> in this hypothetical case, i was assuming len() would be put in object and >> every >> class subclasses object implicitly or explicitly (ie, new style classes >> only). >> if it w

Re: language design question

2006-07-11 Thread vdrab
> >>> isinstance(1, object) > True > > What's 1 . len() ? That's easy! since 1 is actually syntactic sugar for set([set([])]), clearly 1.len() == 1. ;-) v. (actually, make that frozenset([frozenset([])])...) -- http://mail.python.org/mailman/listinfo/python-list

Re: language design question

2006-07-11 Thread Steve Holden
Bryan wrote: > Fredrik Lundh wrote: > >>Bryan wrote: >> >> >>>could you get the same result by putting these methods in base >> >> > class object that everything subclasses? >> >>and how do you make sure that everything subclasses this base class ? >> >> >> > > in this hypothetical case, i was as

Re: language design question

2006-07-11 Thread Fredrik Lundh
"Bryan" wrote: >> and how do you make sure that everything subclasses this base class ? > > in this hypothetical case, i was assuming len() would be put in object and > every > class subclasses object implicitly or explicitly (ie, new style classes only). > if it was done that way, would len(obj)

Re: language design question

2006-07-10 Thread Bryan
Fredrik Lundh wrote: > Bryan wrote: > >> could you get the same result by putting these methods in base > > class object that everything subclasses? > > and how do you make sure that everything subclasses this base class ? > > > in this hypothetical case, i was assuming len() would be put in

Re: language design question

2006-07-10 Thread Steve Holden
Terry Reedy wrote: > "OKB (not okblacke)" <[EMAIL PROTECTED]> wrote in message [...] > > The underlying answer to the original question is that while Pyt;hon is > object-based, it is not strictly OO but is intentionally multiparadigmatic > and will remain so. For instance, no one will be force

Re: language design question

2006-07-10 Thread Steven Bethard
Paul Rubin wrote: > Steven Bethard <[EMAIL PROTECTED]> writes: >> If len() were a method of string objects, you could try using the >> unbound method and writing this as:: >> >> >>> sorted(['aaa', 'bb', 'c'], key=str.len) >> ['c', 'bb', 'aaa'] >> >> But then your code would break on lists

Re: language design question

2006-07-10 Thread Steven Bethard
Bryan wrote: > Steven Bethard wrote: > >> The advantage of a functional form over a method shows up when you >> write a function that works on a variety of different types. Below are >> implementations of "list()", "sorted()" and "join()" that work on any >> iterable and only need to be defined

Re: language design question

2006-07-10 Thread Fredrik Lundh
Bryan wrote: > could you get the same result by putting these methods in base > class object that everything subclasses? and how do you make sure that everything subclasses this base class ? -- http://mail.python.org/mailman/listinfo/python-list

Re: language design question

2006-07-10 Thread Sébastien Boisgérault
Steven Bethard a écrit : > The advantage of a functional form over a method shows up when you write > a function that works on a variety of different types. Below are > implementations of "list()", "sorted()" and "join()" that work on any > iterable and only need to be defined once:: > > [... skip

Re: language design question

2006-07-10 Thread Bruno Desthuilliers
Piet van Oostrum wrote: >>Bruno Desthuilliers <[EMAIL PROTECTED]> (BD) wrote: > > >>BD> Actually, and AFAIK, len(obj) = lambda obj : obj.__len__(). > > > You mean: len = lambda obj : obj.__len__(). yes, of course - not enough caffein, I guess... Thanks -- bruno desthuilliers python -c "p

Re: language design question

2006-07-10 Thread Piet van Oostrum
> Bruno Desthuilliers <[EMAIL PROTECTED]> (BD) wrote: >BD> Actually, and AFAIK, len(obj) = lambda obj : obj.__len__(). You mean: len = lambda obj : obj.__len__(). -- Piet van Oostrum <[EMAIL PROTECTED]> URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4] Private email: [EMAIL PROTECTED] --

Re: language design question

2006-07-10 Thread Ant
>- why is len() not a member function of strings? Instead one says len(w). Coming from a Java background, I also thought this a weird setup. However IMHO there is another good reason to have len(obj) as we do in Python: it helps to enforce some sort of uniformity across code. If I want to fi

Re: language design question

2006-07-10 Thread Fredrik Lundh
"guthrie" wrote: > But if (as I proposed..!) the user interface is better if presented as a > method. one could porovide convenience methods which would then > interface to these underlying library functions; yes? but if it isn't? and why this obsession with superficial syntax details? there's

Re: language design question

2006-07-10 Thread Bruno Desthuilliers
guthrie wrote: > Good point, thanks. > > But if (as I proposed..!) the user interface is better if presented as a > method. one could porovide convenience methods which would then > interface to these underlying library functions; yes? > Actually, and AFAIK, len(obj) = lambda obj : obj.__len__().

Re: language design question

2006-07-10 Thread Paul Rubin
Steven Bethard <[EMAIL PROTECTED]> writes: > If len() were a method of string objects, you could try using the > unbound method and writing this as:: > > >>> sorted(['aaa', 'bb', 'c'], key=str.len) > ['c', 'bb', 'aaa'] > > But then your code would break on lists that weren't strings. s

Re: language design question

2006-07-10 Thread Bruno Desthuilliers
Steven Bethard wrote: > Terry Reedy wrote: > >> "Gregory Guthrie" <[EMAIL PROTECTED]> wrote in message >> news:[EMAIL PROTECTED] >> >>> - why is len() not a member function of strings? Instead one says >>> len(w). >> >> >> Consider >> > map(len, ('abc', (1,2,3), [1,2], {1:2})) >> >> [3, 3, 2

Re: language design question

2006-07-10 Thread Bruno Desthuilliers
Alex Martelli wrote: > Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: >... > >>>This would allow things like: >>>key = '',join( list(word.lower().strip()).sort() ) >> >>key = ''.join(list(sorted(word.lower().strip())) > > > No need to make yet another list here (also, I think eac

Re: language design question

2006-07-09 Thread Bryan
Steven Bethard wrote: > The advantage of a functional form over a method shows up when you write > a function that works on a variety of different types. Below are > implementations of "list()", "sorted()" and "join()" that work on any > iterable and only need to be defined once:: > > def

Re: language design question

2006-07-09 Thread guthrie
Good point, thanks. But if (as I proposed..!) the user interface is better if presented as a method. one could porovide convenience methods which would then interface to these underlying library functions; yes? So the main datatype classes could support such a method style, and just layer on t

Re: language design question

2006-07-09 Thread guthrie
Many thanks; great information. Best, Gregory Steven Bethard wrote: > guthrie wrote: > >> Steven Bethard wrote: >> >>> Why would ``x.len()`` be any more convenient than ``len(x)``? Your >>> preference here seems pretty arbitrary. >> >> -- Perhaps; >> but having all standard operations as a m

Re: language design question

2006-07-09 Thread Steven Bethard
Terry Reedy wrote: > "Gregory Guthrie" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> - why is len() not a member function of strings? Instead one says >> len(w). > > Consider map(len, ('abc', (1,2,3), [1,2], {1:2})) > [3, 3, 2, 1] > > Now try to rewrite this using meth

Re: language design question

2006-07-09 Thread Steven Bethard
guthrie wrote: > Steven Bethard wrote: >> Why would ``x.len()`` be any more convenient than ``len(x)``? Your >> preference here seems pretty arbitrary. > -- Perhaps; > but having all standard operations as a method seems more regular (to > me), and allows a simple chained operation format of a se

Re: language design question

2006-07-09 Thread Terry Reedy
"OKB (not okblacke)" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Terry Reedy wrote: > >> Consider > map(len, ('abc', (1,2,3), [1,2], {1:2})) >> [3, 3, 2, 1] >> >> Now try to rewrite this using methods (member functions). > > [a.len() for a in ('abc', (1,2,3), [1,2], {1:2})]

Re: language design question

2006-07-09 Thread guthrie
Steven Bethard wrote: > Gregory Guthrie wrote: > >> For example, >>- why is len() not a member function of strings? Instead one says >> len(w). > > Why would ``x.len()`` be any more convenient than ``len(x)``? Your > preference here seems pretty arbitrary. -- Perhaps; but having all standa

Re: language design question

2006-07-09 Thread Alex Martelli
Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: ... > > This would allow things like: > > key = '',join( list(word.lower().strip()).sort() ) > > key = ''.join(list(sorted(word.lower().strip())) No need to make yet another list here (also, I think each of you omitted a needed closed-

Re: language design question

2006-07-09 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes: > Length is an obvious property of any one-dimensional non-scalar, not just > strings. As such, it makes sense to have a length function that takes an > argument. As a design decision, it could go either way, but early > Python wasn't fully object-oriente

Re: language design question

2006-07-09 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes: > >> Now try to rewrite this using methods (member functions). > > [a.len() for a in ('abc', (1,2,3), [1,2], {1:2})] > > Did you actually try that? No of course not. It's in a hypothetical python where .len() is a class operation instead of a global fu

Re: language design question

2006-07-09 Thread Erik Max Francis
Steven D'Aprano wrote: > On Sun, 09 Jul 2006 22:45:53 +, OKB (not okblacke) wrote: > >> Terry Reedy wrote: >> >>> Consider >> map(len, ('abc', (1,2,3), [1,2], {1:2})) >>> [3, 3, 2, 1] >>> >>> Now try to rewrite this using methods (member functions). >> [a.len() for a in ('abc', (1,2,3), [

Re: language design question

2006-07-09 Thread Steven D'Aprano
On Sun, 09 Jul 2006 22:45:53 +, OKB (not okblacke) wrote: > Terry Reedy wrote: > >> Consider > map(len, ('abc', (1,2,3), [1,2], {1:2})) >> [3, 3, 2, 1] >> >> Now try to rewrite this using methods (member functions). > > [a.len() for a in ('abc', (1,2,3), [1,2], {1:2})] Did you actually

Re: language design question

2006-07-09 Thread Steven D'Aprano
On Sun, 09 Jul 2006 12:19:13 -0500, Gregory Guthrie wrote: > I am comparing Python to a few other scripting languages, and used a simple > anagrams program as a sample. > > I was surprised ast a few python features that did not work as I would > expect/wish; which caused less compact/expressive

Re: language design question

2006-07-09 Thread Paul Rubin
"Terry Reedy" <[EMAIL PROTECTED]> writes: > Consider > >>> map(len, ('abc', (1,2,3), [1,2], {1:2})) > [3, 3, 2, 1] > > Now try to rewrite this using methods (member functions). [x.len() for x in ('abc', (1,2,3), [1,2], {1:2})] > > - Why doesn't sort() return a value? > > Because it is an in-pl

Re: language design question

2006-07-09 Thread OKB (not okblacke)
Terry Reedy wrote: > Consider map(len, ('abc', (1,2,3), [1,2], {1:2})) > [3, 3, 2, 1] > > Now try to rewrite this using methods (member functions). [a.len() for a in ('abc', (1,2,3), [1,2], {1:2})] -- --OKB (not okblacke) Brendan Barnwell "Do not follow where the path may lead. Go, inste

Re: language design question

2006-07-09 Thread Terry Reedy
"Gregory Guthrie" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > - why is len() not a member function of strings? Instead one says > len(w). Consider >>> map(len, ('abc', (1,2,3), [1,2], {1:2})) [3, 3, 2, 1] Now try to rewrite this using methods (member functions). > - Why d

Re: language design question

2006-07-09 Thread Paddy
Gregory Guthrie wrote: > I am comparing Python to a few other scripting languages, and used a simple > anagrams program as a sample. > > I was surprised ast a few python features that did not work as I would > expect/wish; which caused less compact/expressive program styles that I > wanted - rever

Re: language design question

2006-07-09 Thread Bruno Desthuilliers
Gregory Guthrie a écrit : > I am comparing Python to a few other scripting languages, and used a simple > anagrams program as a sample. > > I was surprised ast a few python features that did not work as I would > expect/wish; which caused less compact/expressive program styles that I > wanted -

Re: language design question

2006-07-09 Thread Steven Bethard
Gregory Guthrie wrote: > For example, >- why is len() not a member function of strings? Instead one says len(w). Why would ``x.len()`` be any more convenient than ``len(x)``? Your preference here seems pretty arbitrary. > - Why doesn't sort() return a value? > > This would allow thing