GNU Free Documentation License . .

()

: ,

( , . reflection) , . , , . [1].

() . , , . , , . , , , , . , (, Smalltalk, ). / (, Java, , ML, Haskell).

[] -

- , - . - , . , - , . , , - , , . - , , . , , .

[]

Brian Cantwell Smith 1982 . [2] [3] meta-circular interpreter, 3-Lisp.


[]

. . .

. , , X Y . X Y . - , X Y; : X, Y.

[]

, , , , . :

. MOO . , , , . : callers() ; , callers()[1] .

, . Objective-C , , , . , , Common Lisp, .

, , .

[]

foo Foo hello ( Hello) . : , .

[] C#

//  
new Foo().Hello();
 
//  
Type type=System.Type.GetType("Foo");
var foo=Activator.CreateInstance(type);
foo.GetType().GetMethod("Hello").Invoke(foo, null);

[] ECMAScript

JavaScript ActionScript:

// 
new Foo().hello()
 
//  
 
// assuming that Foo resides in this
new this['Foo']()['hello']()
 
// or without assumption
new (eval('Foo'))()['hello']()

[] Java

//  
new Foo().hello();
 
//  
Class cls = Class.forName("Foo");
cls.getMethod("hello", null).invoke(cls.newInstance(), null);

[] Qt/C++

Qt C++ / Qt QMetaObject, Qt.

QObject *obj = new QPushButton;
obj->metaObject()->className();             // "QPushButton"
 
QPushButton::staticMetaObject.className();  // "QPushButton"

[] Lua

--  
Foo.hello()
 
--  
_G['Foo']['hello']()

[] Objective-C

//  
Foo *foo = [[Foo alloc] init];
[foo hello];
 
//  
Class cls = NSClassFromString(@"Foo");
id foo = [[cls alloc] init];
SEL selector = NSSelectorFromString(@"hello");
[foo performSelector:selector withObject:nil];

[] Perl

#  
my $foo = Foo->new();
$foo->hello();
 
#  
my $class  = "Foo";
my $method = "hello";
my $object = $class->new();
$object->$method();

[] PHP

// 
$oFoo = new Foo();
$oFoo->hello();
 
// 
$oReflector = new ReflectionClass('Foo');
$oFoo = $oReflector->newInstance();
$oHello = $oReflector->getMethod('hello');
$oHello->invoke($oFoo);
 
//  callback
$oFoo = new Foo();
call_user_func(array($oFoo,'hello'));
 
//    
$class_name = "Foo";
$f = new $class_name();
$method = "hello";
$f->$method();

[] Python

#  
Foo().hello()
 
#  
getattr(globals()['Foo'](), 'hello')()

[] Ruby

#  
Foo.new.hello
 
#  
Object.const_get(:Foo).send(:new).send(:hello)

[] Smalltalk

" "
Foo new hello
 
" "
((Smalltalk at: #Foo) perform: #new) perform: #hello

[] Io

Foo := Object clone do(
    hello := method(
        "Hello" println
    )
)
 
#  
Foo hello
 
#  
getSlot("Foo") getSlot("hello") call

[] ActionScript 3.0

//  
var foo:Foo = new Foo();
foo.hello();
 
//  
var cls:Object = getDefinitionByName("Foo");
var foo:Object = new cls();
foo.hello();

[] Delphi 2010

//  
var
  foo : TFoo;
begin
  foo := TFoo.Create();
  foo.Hello();
end;
 
//  
var
 c : TRttiContext;
 t : TRttiInstanceType;
 foo : TValue;
begin
   c := TRttiContext.Create;
   t := (c.FindType('TFoo') as TRttiInstanceType);
   foo := t.GetMethod('Create').Invoke(t.MetaclassType,[]);
   t.GetMethod('Hello').Invoke(foo,[]);
   c.Free;
end.

[] .

[]

Notes

Documents

[]

[]