Python 1.6 The balanced language

Alex Martelli aleaxit at yahoo.com
Mon Sep 4 12:38:13 EDT 2000


"Suchandra Thapa" <ssthapa at harper.uchicago.edu> wrote in message
news:slrn8r5lof.91f.ssthapa at hepcat.uchicago.edu...
    [snip]
> >Objects with different internal values would behave differently. It's
> >just that instead of modifying an object we create new ones. Eg,
> >imagine that every Python object were immutable, like integers and
> >strings.
>
>     But there wouldn't be any link between class objects and their methods
in
> a pure functional language aside from a logical one in the programmer's
mind.
> Methods in a class would have to explicitly be passed class objects.  In
effect
> you're essentially working with structs and functions on them.

Not so.  Conceptually, you can imagine that somewhere exists a
correspondence table mapping, for each function F with arity X,
(X-tuple of types) -> specific-body-of-function.  The dispatcher
(I'm imagining multidispatch for generality) roots through the
table and find the best-match between the tuple of actual
arguments' actual-runtime-types, and the tuples-of-types in
the table, and calls that specific-body.

(You'll have to have rules guaranteeing that one and only one
best-match always exist, if you want this process to always
result in some call to a specific-body; there are several ways
one could do that; or else, ambiguity in best-matching could
raise exception, in a more dynamic/fluid, less compile-time
typesafe, language).

The fact that the methods thus dispatched are explicitly passed
the objects they work on is no problem -- that's what you have
in Python today ("foo.bar(baz)" to call, and foo's class has a
"def bar(self,baz)" to explicitly receive the 'self', i.e. foo).
Multi-dispatching basically requires this, anyway.

There is no need for objects to be mutable for this style of
programming to be quite handy & practical, particularly with
some language support for the dispatcher part (so that the
various polymorphic versions of F can be specified at suitable
different points in the program)...


Alex






More information about the Python-list mailing list