Why can't static functions be virtual
    Marcio 
    mqmnews123 at sglebs.com
       
    Wed Jan 17 09:07:47 PST 2007
    
    
  
John McAuley wrote:
> I was going to ask why they weren't virtual.
	In Smalltalk they are called class methods and they are virtual.
	| p |
	p := 2 at 3. "an instance of Point"
	p printString. "how a point instance prints itself"
	Point printString. "how the Point class prints itself"
	#printString is sent to class Point on the last line. But it is not 
defined there, so the method lookup/dispatch is done by the VM as usual. 
You get "virtual static".
	This is possible because classes are 1st class citizens at runtime, and 
therefore they are objects too. "Eat your own dog food" - the system is 
implemented in itself. This means that classes have their own classes 
(metaclasses) which hold their MethodDictionary (vtable if you will - 
which, by the way, is an object as well!) and the system is totally 
uniform. In other words,
	p class. "will return Point, the class of all Points"
	Point class. "will return Point's class, a metaclass"
	The system is not infinite (meta meta meta meta ...) because at some 
point the system has a beautiful strange loop. Many such strange loops 
exist in other areas, and if you like a mind bender that covers this 
obscure art of strange loops, see "Godel, Escher, Bach: An Eternal 
Golden Braid" by Douglas R. Hofstadter (ISBN-10: 0465026567).
	It's very useful and powerful to have class methods be virtual as well.
	
marcio
    
    
More information about the Digitalmars-d
mailing list