Re: [Python-3000] Adaptation vs. Generic Functions

2006-04-05 Thread Tim Hochberg
Guido van Rossum wrote: > #!/usr/bin/python2.4 > > """An example of generic functions vs. adaptation. > > After some face-to-face discussions with Alex I'm presenting here two > extremely simplified implementations of second-generation adaptation > and generic functions, in order to contrast and

Re: [Python-3000] pre-PEP: Things that Will Not Change in Python 3.0

2006-04-05 Thread Georg Brandl
Guido van Rossum wrote: > On 4/4/06, Georg Brandl <[EMAIL PROTECTED]> wrote: >> Guido van Rossum wrote: >> > I was going to comment about this one "check it in, we'll add to it >> > later", but then I realized it's not 100% clear whether this is a >> > feature PEP or a meta-PEP? It focuses on featu

Re: [Python-3000] Adaption & generic functions [was Generic functions]

2006-04-05 Thread Walter Dörwald
Guido van Rossum wrote: > On 4/4/06, Tim Hochberg <[EMAIL PROTECTED]> wrote: > [...] >> def __init__(self, name, doc=''): >> self.name = name >> self.registry = {} >> self.__doc__ = doc >> self.all_protocols.add(self) >> def __repr__(self): >> retur

Re: [Python-3000] Adaptation vs. Generic Functions

2006-04-05 Thread Samuele Pedroni
Guido van Rossum wrote: > One followup. Alex mentioned that PyPy used to have its own > implementation of multiple dispatch (which is really the same as > generic functions) but ditched over a year ago. Would Armin or Samuele > care to explain why? Do they no longer like multiple dispatch or was >

Re: [Python-3000] Adaption & generic functions [was Generic functions]

2006-04-05 Thread Nick Coghlan
Walter Dörwald wrote: > But if adapting is done via __call__() we have a problem: Sequence > already provides a __call__, the constructor. Of course if this worked > > print Sequence([1,2,3]).len() > > would look much better than > > print Sequence.adapt([1,2,3]).len() > > but I'm not sure if

Re: [Python-3000] Adaptation vs. Generic Functions

2006-04-05 Thread Nick Coghlan
Tim Hochberg wrote: > So after all of that, I think my conclusion is that I wouldn't refactor > this at all, at least not yet. I'd add support for multiple registration > and possibly spell adapt as __call__, otherwise I'd leave it alone. My > opinion may change after I try ripping out keysof an

Re: [Python-3000] Adaption & generic functions [was Generic functions]

2006-04-05 Thread Walter Dörwald
Nick Coghlan wrote: > [...] > So your example would become: > > class MetaInterface(type): > def __new__(mcl, name, bases, dict): > # Give each class it's own registry > cls = type.__new__(mcl, name, bases, dict) > cls.registry = {} > return cls > >

Re: [Python-3000] Adaptation vs. Generic Functions

2006-04-05 Thread Tim Hochberg
Nick Coghlan wrote: > Tim Hochberg wrote: > >>So after all of that, I think my conclusion is that I wouldn't refactor >>this at all, at least not yet. I'd add support for multiple registration >>and possibly spell adapt as __call__, otherwise I'd leave it alone. My >>opinion may change after I

Re: [Python-3000] Adaptation vs. Generic Functions

2006-04-05 Thread Nick Coghlan
Tim Hochberg wrote: > I like this version. The naming seems an improvement and the > default_adapter seems like a worthy addition. I do keep wondering if > there's some reason for a user of Protocol to call candidate_keys > directly or it's only an implementation detail. If the there is such a

Re: [Python-3000] Adaptation vs. Generic Functions

2006-04-05 Thread Walter Dörwald
Nick Coghlan wrote: > [...] > def default_adapter(self, *args): > """Call result when no adapter was found""" > raise TypeError("Can't adapt %s to %s" % > (args[0].__class__.__name__, self.name)) +1 This makes it easy to add fallbacks: class XReprP

Re: [Python-3000] Adaptation vs. Generic Functions

2006-04-05 Thread Tim Hochberg
Nick Coghlan wrote: > Tim Hochberg wrote: > >>I like this version. The naming seems an improvement and the >>default_adapter seems like a worthy addition. I do keep wondering if >>there's some reason for a user of Protocol to call candidate_keys >>directly or it's only an implementation detail.

Re: [Python-3000] String formating operations in python 3k

2006-04-05 Thread John J Lee
[Greg Ewing] > I'm more interested in long-term readability > and maintainability than in pandering to one-off > impressions when coming from another language. [Ian Bicking] > $-based substitution is very common. Like most languages, Python uses > () for calling functions, it uses keywords like "

Re: [Python-3000] String formating operations in python 3k

2006-04-05 Thread John J Lee
On Wed, 5 Apr 2006, Greg Ewing wrote: [...] > There are other problems with the $ syntax too. > The lack of an explicit closing marker causes > problems when the parameter is immediately > followed in the string by an alphanumeric > character. You end up having to allow some > kind of bracketing as

Re: [Python-3000] String formating operations in python 3k

2006-04-05 Thread John J Lee
On Tue, 4 Apr 2006, Barry Warsaw wrote: [...] > Yes, I think this is where we differ. $thing in it's most common > form is more readable to me than {thing}, and while the former is > equivalent to ${thing} with string.Template's defaults, I find it's > very rarely used. Regardless of readability,

Re: [Python-3000] String formating operations in python 3k

2006-04-05 Thread Talin
Greg Ewing canterbury.ac.nz> writes: > I'm also not all that keen on $, either inside > or outside the string. It seems to me that > something like > >"User {user} has printed {n} pages" FWIW, this is very similar to the syntax used in the .Net function String.Format (I think Java uses a si

Re: [Python-3000] String formating operations in python 3k

2006-04-05 Thread Tim Hochberg
Ian Bicking wrote: > Alex Martelli wrote: > >>As for the % operator, I never liked it -- either a builtin function, >>or even better a method of string objects, is going to be much more >>readable (and my preference would be to have it take optional >>positional arguments, corresponding to {

Re: [Python-3000] String formating operations in python 3k

2006-04-05 Thread Ian Bicking
Tim Hochberg wrote: > Ian Bicking wrote: >> Alex Martelli wrote: >>> As for the % operator, I never liked it -- either a builtin >>> function, or even better a method of string objects, is going to be >>> much more readable (and my preference would be to have it take >>> optional positional a

Re: [Python-3000] Adaptation vs. Generic Functions

2006-04-05 Thread Guido van Rossum
Fascinating ideas in this thread! I spent some time blogging about this on artima: http://www.artima.com/weblogs/viewpost.jsp?thread=155123 I have to write my slides for a talk about Py3K later today, but I'll be back. In the mean time I've rejected PEPs 245 and 246 in expectation of something be

Re: [Python-3000] Adaptation vs. Generic Functions

2006-04-05 Thread Walter Dörwald
Guido van Rossum wrote: > Fascinating ideas in this thread! > > I spent some time blogging about this on artima: > http://www.artima.com/weblogs/viewpost.jsp?thread=155123 > > I have to write my slides for a talk about Py3K later today, but I'll > be back. In the mean time I've rejected PEPs 245

[Python-3000] Interfaces (was: Re: Adaptation vs. Generic Functions)

2006-04-05 Thread Ian Bicking
Guido van Rossum wrote: > Fascinating ideas in this thread! It's certainly been interesting to see convergence coming from both directions independently. > I spent some time blogging about this on artima: > http://www.artima.com/weblogs/viewpost.jsp?thread=155123 > > I have to write my slides f

Re: [Python-3000] Interfaces (was: Re: Adaptation vs. Generic Functions)

2006-04-05 Thread Guido van Rossum
On 4/5/06, Ian Bicking <[EMAIL PROTECTED]> wrote: > Guido van Rossum wrote: > > I have to write my slides for a talk about Py3K later today, but I'll > > be back. In the mean time I've rejected PEPs 245 and 246 in > > expectation of something better that's imminent! > > Is PEP 245 ("Python Interfac

Re: [Python-3000] Adaptation vs. Generic Functions

2006-04-05 Thread Tim Hochberg
Walter Dörwald wrote: > Guido van Rossum wrote: > >> Fascinating ideas in this thread! >> >> I spent some time blogging about this on artima: >> http://www.artima.com/weblogs/viewpost.jsp?thread=155123 >> >> I have to write my slides for a talk about Py3K later today, but I'll >> be back. In the m

Re: [Python-3000] Adaptation vs. Generic Functions

2006-04-05 Thread Guido van Rossum
On 4/5/06, Tim Hochberg <[EMAIL PROTECTED]> wrote: > Walter Dörwald wrote: > > What's still missing IMHO is a way for an adapter to defer to the next > > adapter in the chain, i.e. something like: [...] > The concept seems good, but I find the implementation baffling, OK, I > finally figured it out

Re: [Python-3000] Adaptation vs. Generic Functions

2006-04-05 Thread Ian Bicking
Walter Dörwald wrote: > Guido van Rossum wrote: > > >>Fascinating ideas in this thread! >> >>I spent some time blogging about this on artima: >>http://www.artima.com/weblogs/viewpost.jsp?thread=155123 >> >>I have to write my slides for a talk about Py3K later today, but I'll >>be back. In the mea

Re: [Python-3000] Adaptation vs. Generic Functions

2006-04-05 Thread Tim Hochberg
Guido van Rossum wrote: >On 4/5/06, Tim Hochberg <[EMAIL PROTECTED]> wrote: > > >>Walter Dörwald wrote: >> >> >>>What's still missing IMHO is a way for an adapter to defer to the next >>>adapter in the chain, i.e. something like: >>> >>> >[...] > > >>The concept seems good, but I fin

Re: [Python-3000] Adaptation vs. Generic Functions

2006-04-05 Thread Guido van Rossum
On 4/5/06, Tim Hochberg <[EMAIL PROTECTED]> wrote: > I'm hoping that Walter can give some more realistic examples since I > don't have real-world experience here. The basic idea is simply to let > an adapter give up and let the protocol try the next adapter. This could > happen in a generic functio

Re: [Python-3000] Adaptation vs. Generic Functions

2006-04-05 Thread Jim Jewett
> Walter Dörwald wrote: > > What's still missing IMHO is a way for an adapter > > to defer to the next adapter in the chain Tim Hochberg <[EMAIL PROTECTED]> wrote: > Why not simply raise a DeferToNextAdapter exception? It sounds good at first, but it may be overengineered. If that means "NotImpl

Re: [Python-3000] Adaptation vs. Generic Functions

2006-04-05 Thread Walter Dörwald
Guido van Rossum wrote: > On 4/5/06, Tim Hochberg <[EMAIL PROTECTED]> wrote: >> I'm hoping that Walter can give some more realistic examples since I >> don't have real-world experience here. The basic idea is simply to let >> an adapter give up and let the protocol try the next adapter. This could

Re: [Python-3000] Adaptation vs. Generic Functions

2006-04-05 Thread Walter Dörwald
Tim Hochberg wrote: > Guido van Rossum wrote: > >> On 4/5/06, Tim Hochberg <[EMAIL PROTECTED]> wrote: >> >> >>> Walter Dörwald wrote: >>> >>> What's still missing IMHO is a way for an adapter to defer to the next adapter in the chain, i.e. something like: >> [...] >

Re: [Python-3000] Adaptation vs. Generic Functions

2006-04-05 Thread Guido van Rossum
On 4/5/06, Walter Dörwald <[EMAIL PROTECTED]> wrote: > Guido van Rossum wrote: > > > On 4/5/06, Tim Hochberg <[EMAIL PROTECTED]> wrote: > >> I'm hoping that Walter can give some more realistic examples since I > >> don't have real-world experience here. The basic idea is simply to let > >> an adapt

Re: [Python-3000] Adaptation vs. Generic Functions

2006-04-05 Thread Walter Dörwald
Guido van Rossum wrote: > On 4/5/06, Walter Dörwald <[EMAIL PROTECTED]> wrote: >> Guido van Rossum wrote: >> >>> On 4/5/06, Tim Hochberg <[EMAIL PROTECTED]> wrote: I'm hoping that Walter can give some more realistic examples since I don't have real-world experience here. The basic idea is

Re: [Python-3000] String formating operations in python 3k

2006-04-05 Thread Jim Jewett
On 4/4/06, Ian Bicking <[EMAIL PROTECTED]> wrote: > Alex Martelli wrote: > > As for the % operator, I never liked it -- either a builtin function, > > or even better a method of string objects, is going to be much more > > readable (and my preference would be to have it take optional > > positional

[Python-3000] Adaptation vs. Generic Functions

2006-04-05 Thread Phillip J. Eby
Guido wrote: >Does anybody know if Phillip Eby's generic functions support this? Yes, and yes, they do. :) At least, the multiple-dispatch ones do. You can add a 'next_method' argument to the front of a method's arguments, and it's automatically passed the next applicable callable. (Which c

Re: [Python-3000] Adaptation vs. Generic Functions

2006-04-05 Thread Tim Hochberg
Walter Dörwald wrote: > Guido van Rossum wrote: > >> On 4/5/06, Walter Dörwald <[EMAIL PROTECTED]> wrote: >> >>> Guido van Rossum wrote: >>> On 4/5/06, Tim Hochberg <[EMAIL PROTECTED]> wrote: > I'm hoping that Walter can give some more realistic examples since I > don't have real

Re: [Python-3000] Adaptation vs. Generic Functions

2006-04-05 Thread Walter Dörwald
Tim Hochberg wrote: > Walter Dörwald wrote: > >> Guido van Rossum wrote: >> >>> On 4/5/06, Walter Dörwald <[EMAIL PROTECTED]> wrote: >>> Guido van Rossum wrote: > On 4/5/06, Tim Hochberg <[EMAIL PROTECTED]> wrote: > >> I'm hoping that Walter can give some more realistic exam

Re: [Python-3000] String formating operations in python 3k

2006-04-05 Thread Greg Ewing
Alex Martelli wrote: > > and my preference would be to have it take optional > positional arguments, corresponding to {1}, {2}, etc, and optional > named arguments, corresponding to {name} &c). Yes, certainly. -- Greg ___ Python-3000 mailing list P

Re: [Python-3000] String formating operations in python 3k

2006-04-05 Thread Greg Ewing
Ian Bicking wrote: > Note that if it takes keyword arguments, but doesn't take a single > dictionary-like object (like % and string.Template.substitute do), then > you lose any ability to use clever or interesting dictionary-like > objects for substitution. If you subclass your clever object f

Re: [Python-3000] Adaptation vs. Generic Functions

2006-04-05 Thread Guido van Rossum
On 4/5/06, Tim Hochberg <[EMAIL PROTECTED]> wrote: > It seems like you can chain protocols like that simply by setting up an > appropriate default_adapter method. For example, if we already had a > pprinter protocol, we could define one that subclassed it and customized it: > > class CustomPPrintPr

Re: [Python-3000] String formating operations in python 3k

2006-04-05 Thread Greg Ewing
Ian Bicking wrote: > Clever and interesting would include my quoting, evaluating, and > formatting wrappers. It might also include special gettext expressions, > case insensitivity, or other interesting wrappers. Hmmm, *that* degree of cleverness would be better served by a different interface

Re: [Python-3000] Adaptation vs. Generic Functions

2006-04-05 Thread Guido van Rossum
On 4/5/06, Walter Dörwald <[EMAIL PROTECTED]> wrote: > The problem with this is that it looks in the base protocol only if the > the class can't be found in the registry of the subprotocol. This mean > that an adapter from the subprotocol might be used, although the base > protocol has a "better" a

Re: [Python-3000] String formating operations in python 3k

2006-04-05 Thread Greg Ewing
Ian Bicking wrote: > ** can't be changed > in this way, either -- it really has to enumerate all the keys in the > thing passed to it, In Py3k this could perhaps be different in the case where you're calling a function defined like def f(*args, **kwds): ... In that case there are no n

Re: [Python-3000] String formating operations in python 3k

2006-04-05 Thread Ian Bicking
Greg Ewing wrote: > Ian Bicking wrote: > >> Clever and interesting would include my quoting, evaluating, and >> formatting wrappers. It might also include special gettext >> expressions, case insensitivity, or other interesting wrappers. > > Hmmm, *that* degree of cleverness would be better >

Re: [Python-3000] String formating operations in python 3k

2006-04-05 Thread Ian Bicking
Greg Ewing wrote: > Ian Bicking wrote: > >> ** can't be changed in this way, either -- it really has to enumerate >> all the keys in the thing passed to it, > > In Py3k this could perhaps be different in the case where > you're calling a function defined like > > def f(*args, **kwds): > .

Re: [Python-3000] Adaptation vs. Generic Functions

2006-04-05 Thread Tim Hochberg
Guido van Rossum wrote: [TAHs simple pprint customization example snipped] >> >>Nice! >> >>I expect that with another dozen lines of code I could make custom >>pretty printers possible, although the way the customization happens >>might be a little kludgy. I'll look into it. > > > Neat indeed.

Re: [Python-3000] String formating operations in python 3k

2006-04-05 Thread Greg Ewing
Ian Bicking wrote: > Why? The wrappers looked pretty darn simple to me. I suppose they'd be > slightly simpler if you replaced __getitem__ with __call__. What I meant was that another method or function could be provided that takes a mapping object as a direct argument, rather than trying to s

Re: [Python-3000] String formating operations in python 3k

2006-04-05 Thread Ian D. Bollinger
On 4/5/06, John J Lee <[EMAIL PROTECTED]> wrote: But how about putting them at the start, after the $?  That way, theformat character can't get mixed up with the text following it.  Forexample, $r{foo} would mean the same as the current %(foo)r. This is somewhat tangental, but hopefully an $r forma

Re: [Python-3000] Adaptation vs. Generic Functions

2006-04-05 Thread Walter Dörwald
Guido van Rossum wrote: > On 4/5/06, Walter Dörwald <[EMAIL PROTECTED]> wrote: >> The problem with this is that it looks in the base protocol only if the >> the class can't be found in the registry of the subprotocol. This mean >> that an adapter from the subprotocol might be used, although the ba