On Mon, Jun 1, 2015 at 4:59 PM, BartC <b...@freeuk.com> wrote: > I'm developing a new language along the lines of Python, perhaps a brief > description of how things are done there might help. Or just give a > different perspective. > > Objects in this language are tagged: there's a code attached to each > indicating what kind of data is stored. These codes are integers, or > enumerations, for example: > > Int = 1 > String = 2 > List = 3 > Class = 4 > > And the following are examples of object instances with their tags: > > a is (Int, 42) > b is (String, "ABCXYZ") > c is (List, [10,20,30,40]) > d is (Class, 2 or <String>) > > The last one might be tricky to grasp: it's really just a number, but one > that represents a class or type (or tag). If printed, it could display > <String> rather than just 2. (And when used to do something with the class, > the 2 might be an index into a set of tables.) > > d is not /the/ class itself, but just a reference to it (this is pseudo-code > not Python): > > print (b) => ABCXYZ > print (typeof(b)) => String <2> > > print (d) => String <2> > print (typeof(d)) => Class <4> > print (typeof(typeof(d))) => Class <4> > > In my own language, the connection between class and type is hazy (I've only > just added classes so it needs to be hazy until I understand them more). > > 'Type' includes everything, including all the built-in types such as the > tags above, but also user-defined classes. In fact classes are the mechanism > used to define new types. But with both designated by an integer within the > same band (eg. built-int types 1 to 20, user-defined classes 21 and up), it > is easier not to have a strong distinction ... at the moment. > > I haven't a root class yet that is the base of all the others. I don't think > it's necessary internally to make things work. But it might be a useful > concept in the language. Calling it 'object' however might give rise to > confusion as 'object' is informally used to refer to instances. (I've never > used OO but have picked up some of the jargon!) > > (This is almost certainly not how Python does things. Although the Python > language doesn't go into details as to its implementation provided the > behaviour is correct.)
It sounds quite similar to me. In CPython at least, every object has a direct pointer to its type rather than an array index (which is essentially just an offset from a pointer). -- https://mail.python.org/mailman/listinfo/python-list