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

Erik Max Francis max at alcyone.com
Fri Dec 20 04:44:55 EST 2002


Bengt Richter wrote:

> I see no reason not to allow expression of a dict's use in the role of
> its functional twin by simply appending () instead of [], or
> disallowing
> passing a reference to the dict where it will be interpreted in terms
> of the functional twin.

Given the state of affairs, a distinction is made between mappable and
callable.  The builtin dictionary type implements the former and not the
latter.  You're asking it to implement both just for the heck of it.  I
don't think "I see no reason not to allow ..." is going to get you very
far here, since you're the one asking for the change.  The real issue
is, "What are good reasons _to_ allow it?"  The fact that you can wrap a
mappable in a callable interface, lambda or not, with a trivial
one-liner is a good indication that there's no need for it to be done in
the language itself.

> It is obvious that one would prefer the
> efficiency
> of a dict over coding something like the above, but how about dealing
> with
> an unpredictable mix where advantages go both ways? Why force an
> unnecessary
> wrapper?

It's not an "unnecessary wrapper."  Someone else may want to override
dicts so that his ExecutableDict has a normal mapping interface _and_ a
callable interface that does something completely unrelated. 

I mean, seriously.  How often do you _really_ find yourself wanting to
use a dictionary in a situation that expects a callable and what you
really want is to transform that call into a mapping lookup with
absolutely no changes whatsoever?  I can't think of a single time I've
encountered this, and your example of sorting was, quite frankly, really
stretched.

You're making an argument from theoretical grounds that I don't think
anyone is going to buy on their face value -- that is, anyone who would
be willing to incorporate that change on those theoretical arguments
alone -- so now you're going to have to come up with quite a few
real-world cases where it really is so fabulously convenient to do so
that it wins everyone over.  I don't see that happening.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ But since when can wounded eyes see / If we weren't who we were
\__/ Joi
    7 Sisters Productions / http://www.7sisters.com/
 Web design for the future.



More information about the Python-list mailing list