Re: Thoughts and proposals about types and classes

Jack Jansen (Jack.Jansen@cwi.nl)
Fri, 10 Sep 1993 11:16:45 +0200

I have been thinking along the lines of something where you could ask
python 'would it be ok if I tried to do <this> with <that>?', which is
often what you use type() for.

An example:
def oldstyle(x):
if type(x) in (type(()), type([])):
for i in range(len(x)):
print i, x[i]
else:
print x

def newstyle(x):
if allowed(x[0]):
for i in range(len(x)):
print i, x[i]
else:
print x

This allowed() builtin would also obviate the need for the horrible
'type(x) in (type(0), type(0L), type(0.0), etc)' constructs, by
allowing you to ask 'allowed(x+1)'.

There's a potential implementation problem with allowed(), though,
depending on how syntax analysis/execution work. Hmpf, where is Guido
when you need him...

--
Jack Jansen        | If I can't dance I don't want to be part of
Jack.Jansen@cwi.nl | your revolution             -- Emma Goldman
uunet!cwi.nl!jack    G=Jack;S=Jansen;O=cwi;PRMD=surf;ADMD=400net;C=nl