Builtin dict should be callable, since a dict defines a function

Erik Max Francis max at alcyone.com
Thu Dec 19 23:50:10 EST 2002


Bengt Richter wrote:

> IMO various uses are red herrings.

You're going to have a hard time selling the idea unless you can give
examples where the change makes things obviously much better.  It's
going to be awfully difficult to do that, since it's _trivial_ to define
a callable interface that simply translates to the mapping interface
yourself.  Since that is so ridiculously easy (one line of code), it's
really hard to justify the change for _everyone_ just because one person
thinks it might be a good idea for abstract reasons.

> What needs to be justified is an
> existing limitation on uniform passing of references to standard
> objects
> that implement the same functionality, just for lack of a trivial
> alternative
> compatible interface.

It's not a limitation, it's a clear distinction between mapping and
callable.  There are cases when those purposes may be similar, and cases
where they may not.  As it stands, Python, makes a clear distinction
between the two.  You can define an object that has _both_ a mapping
interface _and_ a callable interface.  Would it be a good idea define
such objects?  I don't know.  But you should be able to do it, since
mapping/subscripting and calling are not the same thing.

What you are proposing _is_ an unnecessary limitation (conjoining two
otherwise separate actions), not  the lifting of a limitation.

> You don't see a commonality in the abstract?

There's a commonality in the abstract, of course, in that there is an
interface and that allows you to "do" something.  In a mappable
interface, the "doing" is subscripting; in a callable one, it's calling.
But should you extend that philosophy to everything, you end up with one
"do" operation for every interface.  That's obviously not a pleasant
trend.

> No one would be forced to use an additional interface that doesn't
> [exist] now ;-)

But there is no inherent value in adding the equivalence, because it's a
false equivalence.  The two different interfaces exist so that a
distinction can be made between them.  You want to remove that
distinction which is there deliberately.  Why?

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ Whoever contends with the great sheds his own blood.
\__/ Sa'di
    Lsystem / http://www.alcyone.com/pyos/lsystem/
 A Lindenmayer systems explorer in Python.



More information about the Python-list mailing list