[Types-sig] Re: Meta-classes discussion starter

John Skaller skaller@maxtal.com.au
Thu, 03 Dec 1998 21:25:43 +1000


At 21:49 2/12/98 -0500, Tim Peters wrote:
>[John]
>>         You're not following.
>
>You're not anticipating <wink>.

        I have to pay that :-)

>> I'm analysing the _structure_ of a system. I'm telling you classes are
>> _isomorphic_ to functions; and providing the isomorphism.
>
>Up above, yes; below, no.  You went quite a ways beyond casting the
>semantics in functional form:  (A) you want others to adopt that view of
>semantics too; 

        No, I don't want other to adopt it, I want them to use
it as an analysis tool, to understand what meta-programming is all 
about.

        If one were to assume classes were functions and
do a functional analysis of what meta-programming is
from that viewpoint, one might be able to take the results
and map them _back_ onto a class model to get meta-classes.

>and, (B) you want programmatic support for that view added to
>Python.

        I want some specific functions added to builtins,
because (a) I need them and (b) I know that they're
enough to do all meta-programming. I have theorems that prove
it. I have constructions for all the common data structures
in a book, including stacks, queues, iterators, arrays.
[RFC Walters, Categories in Computer Science]

>> I didn't claim 'python was a functional language'.
>
>No, I hardly think anyone would.  You do want to move it in that direction,
>though, don't you?  

        No, I don't. I want to move in the direction a categorical
programming system would take. That requires throwing out
encapsulation (which Python doesn't enforce anyhow) and emphasising
second order constructions [operations on function] rather than
first order ones [operations on data structures]. Because that is
what 'meta' means.

        It's quite clear this is what meta-classes are about:
defining how classes define instances.

        And the 'class is a function' view shows, in the abstract,
what is required IMHO: you have to be able to construct functions dynamically.

>> My suggestion is for more builtin functions, of the kind needed
>> to construct functions.
>
>>> How about a specific proposal?

        I would not waste my time without some support.
I have learned this from 5 years on ISO Standardisation
committees. People against it will argue every which way
against it, and without an implementation it isn't possible
to provide a demonstration of utility.

        I am in fact constructing these objects:
see the 'felix' subsystem of interscript.

        I am writing here only to try to prevent
adding yet another hack that doesn't quite work to
a programming language. See C++. I don't want that
to happen to Python: it has enough non-orthogonal
implementation hacks -- such as classes -- already.

>>         There is some code available for browsing.
>
>How about a specific proposal?

        Sure:

        compose(f1, f2, f3, f4 ..) # chain in series, 1 arg only
        product(f1, f2, f3, f4, ..) # apply componentwise (in parallel)
        sum(f1, f2, .. ) # select one of
        delta(x,i) = (x,x,x,x,x ..) # i times

there are a few more. I will have to look up the book.
Sum needs explanation: it is called like

        f(x, i) # return fi(x)

There is also a case to expand the set of available
quantifiers. (reduce is a quantifier, i.e. a loop)

Most of these constructions are available in C++ STL.
They're the basis of (generic) programming.

The constructions above are precisely what is needed to
build all flowcharts. if you can do that, you can
build _any_ function dynamically, given some suitable
primitives to combine.

So I am not asking for any major changes, I'd like a
basis: i.e. a set of constructions spanning the
whole space. Given those, new more convenient ones
can be defined, and the most used of these can
be re-implemented later in C when it is known
which ones are used most, or need the most speed
improvements.

For example, to compose two functions, one might
actually concatenate the opcodes.

IF you have these facilities available, you can actually
start talking about implementing meta-classes. if you really
want to. After all, aren't they meant to be a _general_ way to
define something that defines a class? And what is that, other
than a way of writing a 'mini' compiler which places an
arbitrary interpretation on a class definition?
And isn't that minicompiler just a function?
-------------------------------------------------------
John Skaller    email: skaller@maxtal.com.au
		http://www.maxtal.com.au/~skaller
		phone: 61-2-96600850
		snail: 10/1 Toxteth Rd, Glebe NSW 2037, Australia