[Types-sig] Suggestions for python 2

skaller skaller at maxtal.com.au
Mon Jan 17 09:36:40 EST 2000


Edward Welbourne wrote:
> 
> I have been thinking about the namespace types.
> That's modules, packages, classes and instances.
> I believe they could profitably be united into *one* type.
> Along the way, I see some constructive uniformisations we could apply.

	Sigh. See Viper. Modules, packages, classes, instance,
raw objects, local scopes .. and some other scopes .. are all
'unified' in two ways:

	1) Support for an 'environment' protocol supporting
unqualified name lookup

	2) Support for qualified lookup [x.y]
 
	In Viper, 'environment' is a fundamental abstraction
of the execution environment: there's an actual class interface
abstraction
for it. Qualified lookup is supported by ad-hoc polymorphism, more or
less
encapsulated in the 'getattr' 'setattr' 'hasattr' functions.

>   * namespaces that you can't modify once they have been initialised
>   * namespaces in which attribute-modification is type-checked

	As you can see, in Viper, there are _two_ dual concepts
of namespaces. In both cases, the fundamental implementation involves
dictionaries, plus extra structure.

>   * hybrids of those with assorted degrees of control
>   * certain tools the functional programmers crave, notably a truly
>     faithful implementation of currie()

	not required: python lambdas subsume what can be done with
	currying.

>   * some of the truly whacky `metaclass' proposals

	There are plenty of them :-)
 
	See Viper. It already supports generic types, eg lists of 
X for any type X. This is done fairly easily by making

	ListOf a class with one attribute 'type'
	ListOf(X) an instance with type = X

and that instance the type of a raw object with a normal list
as it's only attribute. Methods of the ListOf class have
two objects: the type object, (ListOf(X)), and the list instance (self).
These are both bound by the two stage lookup, so that a method
like 

	def append(typeobj, self, value):
		if type(value) is not typeobj.type: 
			raise TypeError
		else:  self.list.append(value)

> I intend to push this proposal during IPC8.  I would greatly appreciate
> constructive comments in advance, if only to temper my enthusiasm ;^}

	The lookup mechanism in Viper is very powerful.
It is not necessarily 'right'. It might be useful to examine
a working implementation? After all, it more or less models
what C Python 1.5.2 does now, and just relaxes some restrictions
on what a type object can be.

	[Viper raw objects can also be metamorphic -- that is,
change type dynamically -- the type is 'just another attribute']

-- 
John (Max) Skaller, mailto:skaller at maxtal.com.au
10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850
download: ftp://ftp.cs.usyd.edu/au/jskaller




More information about the Python-list mailing list