Re: [Python-3000] Proposal: Metasyntax operator

2006-07-25 Thread Greg Ewing
Ivan Krstic wrote: > Python already has > just enough programmable bits in place to invite abuse which emulates > programmable syntax; look at SQLObject or SQLalchemy for examples. Also, the "just use a string" workaround means that people are effectively doing this anyway, but in an uglier and le

Re: [Python-3000] callable()

2006-07-25 Thread Greg Ewing
Andrew Koenig wrote: > I think of a > function f as being idempotent if f(x) == x for all x in dom(f). Um, that's an identity function, isn't it? I think you mean something more like f(f(x)) == f(x). But even that's not quite what we're talking about here, because we're not hashing the result of

Re: [Python-3000] callable()

2006-07-25 Thread Stefan Behnel
Collin Winter wrote: > On 7/25/06, Andrew Koenig <[EMAIL PROTECTED]> wrote: >>> With your CD example, you need an external resource (the CD itself) in >>> order to calculate the hash - in that case, you can't safely defer >>> the hash calculation until the first time you know you need it, >>> sinc

Re: [Python-3000] callable()

2006-07-25 Thread Guido van Rossum
Ouch, that's a problem indeed. There's not really a clean way out unfortunately: either we remove object.__hash__ and let hash() do the default implementation, and then presence of __hash__ is no longer an indicator of hashability; or we keep it, and override it to raise an exception in unhashable

Re: [Python-3000] callable()

2006-07-25 Thread Collin Winter
On 7/25/06, Andrew Koenig <[EMAIL PROTECTED]> wrote: > > With your CD example, you need an external resource (the CD itself) in > > order to calculate the hash - in that case, you can't safely defer > > the hash calculation until the first time you know you need it, > > since you don't know whether

Re: [Python-3000] callable()

2006-07-25 Thread Giovanni Bajo
Andrew Koenig wrote: > It's still the case that evaluating a hash might be expensive the > first time you do it, so you may want to be able to test whether it > can be done and actually do it only later. I think you're doing a lot of guess-work here. In real world situations, computing the hash i

Re: [Python-3000] callable()

2006-07-25 Thread Andrew Koenig
> With your CD example, you need an external resource (the CD itself) in > order to calculate the hash - in that case, you can't safely defer > the hash calculation until the first time you know you need it, > since you don't know whether or not you'll have access to the > physical CD at that point

Re: [Python-3000] Proposal: Metasyntax operator

2006-07-25 Thread Ivan Krstic
Guido van Rossum wrote: > I'd like to see this fall under the blanket "Python will not have > programmable syntax" rule in PEO 3099. Why? I understand your general position, but categorically rejecting anything smelling of metasyntax seems ill-conceived to me. Python already has just enough progr

Re: [Python-3000] callable()

2006-07-25 Thread Nick Coghlan
Andrew Koenig wrote: >> All of which is a long-winded way of saying "calculation of an object hash >> should be both cheap and idempotent" :) > > Actually, I disagree -- I don't see why there's anything wrong with a hash > being expensive to calculate the first time you do it. True, but if you ca

Re: [Python-3000] callable()

2006-07-25 Thread Andrew Koenig
> All of which is a long-winded way of saying "calculation of an object hash > should be both cheap and idempotent" :) Actually, I disagree -- I don't see why there's anything wrong with a hash being expensive to calculate the first time you do it. For example, consider a string type in which the

Re: [Python-3000] callable()

2006-07-25 Thread Nick Coghlan
Andrew Koenig wrote: >> In both cases, __hash__ is not idempotent, and is thus an abomination. > > Why do you say it's not idempotent? The first time you call it, either it > works or it doesn't. If it doesn't work, then you shouldn't have called it > in the first place. If it does work, all su