Smalltalk and Python
sandj.williams at gte.net
Fri Dec 15 10:31:06 EST 2000
Andrew Dalke wrote:
> Greg Ewing wrote:
> >the TADS (Text Adventure Development System)
> >lets you declare objects with multiple
> >classes, e.g.
> > bed: Furniture, Surface, Scenery
> > ...
> >This is really just syntactic sugar,
> >To mention something vaguely Python-relevant:
> >if Python had a convenient syntax for declaring
> >singletons, it could be a pretty good language for
> >Interactive Fiction...
> One packet of syntactic sugar, coming up!
> def make_a(*classes):
> class make_a:
> make_a.__bases__ = tuple(classes)
> return make_a()
> class Furniture:
> def comfy(self): return 1
> class Surface:
> def genus(self): return 0 # Imagine a spherical cow...
> class Scenery:
> def description(self): return "boring"
> >>> bed = make_a(Furniture, Surface, Scenery)
> >>> bed
> <__main__.make_a instance at 0x120330628>
> >>> bed.description()
> >>> bed.genus()
> >>> bed.comfy()
> dalke at acm.org
A cow is genus 1
More information about the Python-list