On 01/06/2015 13:03, Eddilbert Macharia wrote:
Thank you all who have taken there time to assist me.
Special thanks to Steven D'Aparo even though you didn't have two you have taken 
you time to go into details.

I think i kind of understand now.

Instead of python having data types like int, string, e.t.c it has two 
primitive types which are class type and class object which are created by 
python interpreter during its setup .using this two classes python is able to 
create some more data types

In some context type means the data type an object is e.g. an int,string e.t.c.

In the new class style, type and class sort of mean the same thing.

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.)

--
Bartc
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to