Any language where every class instance is a class too?
- by Dokkat
Taking inspiration from Javascript prototypes, I had the idea of a language where every instance can be used as a class.
Before I potentially reinvent the wheel, I would like to ask if there is a language already using this concept:
//To declare a Class, extend the base class (in this case, Type)
Type(Weapon,{price:0});
//Same syntax to inherit; simply extend the parent:
Weapon(Sword,{price:3});
Weapon(Axe,{price:4});
Sword(Katana,{price:7});
Sword(Dagger,{price:3});
//And the same to create an instance:
Katana(myKatana,{nickname:"Leon"});
myKatana.price; // 7
myKatana.nickname; // Leon
// An operator to return children of a class;
Sword_; // [Katana, Dagger]
// An operator to return array of descendants;
Sword__; // [Katana, Dagger, myKatana]
// An operator to return array of parents;
Sword^; // Weapon
// Arrays can be used as elements
Sword__.price += 1; //increases price of Sword's descendants by 1
mySword.price; //8
// And to access specific element (using its name instead of index)
var name = "mySword"
Katana_[name]; // [mySword]
Katana_[name].nickname; // Leon
Has this kind of approach been already studied/implemented?