Reflection/List methods: Difference between revisions

Add Ecstasy example
m (syntax highlighting fixup automation)
(Add Ecstasy example)
 
(5 intermediate revisions by 3 users not shown)
Line 118:
opEquals
factory</pre>
 
=={{header|Ecstasy}}==
For any object, the type of that object provides access to its methods and functions:
 
<syntaxhighlight lang="ecstasy">
module test {
void run() {
@Inject Console console;
 
String[] names = &this.actualType.multimethods.keys.toArray();
console.print($"Method/function names on {this}: {names}");
 
Method[] methods = &this.actualType.methods;
console.print($"The methods of {this}: {methods}");
 
Function[] functions = &this.actualType.functions;
console.print($"The functions of {this}: {functions}");
}
}
</syntaxhighlight>
 
{{out}}
<pre>
x$ xec test
Method/function names on test: [toString, makeImmutable, to, estimateStringLength, appendTo, exTo, toEx, exToEx, isModuleImport, classForName, typeForName, run, hashCode, maxOf, notGreaterThan, compare, equals, minOf, notLessThan]
The methods of test: [String toString(), immutable Object makeImmutable(), Range<Orderable> to(Orderable that), Int estimateStringLength(), Appender<Char> appendTo(Appender<Char> buf), Range<Orderable> exTo(Orderable that), Range<Orderable> toEx(Orderable that), Range<Orderable> exToEx(Orderable that), conditional Module isModuleImport(), conditional Class classForName(String name), conditional Type typeForName(String name), void run()]
The functions of test: [Int hashCode(Type<Package> CompileType, CompileType value), CompileType maxOf(Type<Orderable> CompileType, CompileType value1, CompileType value2), CompileType notGreaterThan(Type<Orderable> CompileType, CompileType value1, CompileType value2), Ordered compare(Type<Const> CompileType, CompileType value1, CompileType value2), Boolean equals(Type<Package> CompileType, CompileType value1, CompileType value2), CompileType minOf(Type<Orderable> CompileType, CompileType value1, CompileType value2), CompileType notLessThan(Type<Orderable> CompileType, CompileType value1, CompileType value2)]
</pre>
 
=={{header|Elena}}==
ELENA 56.0x :
<syntaxhighlight lang="elena">import system'routines;
import system'dynamic;
Line 136 ⟶ 164:
var o := new MyClass();
o.__getClass().__getMessages().forEach::(p)
{
console.printLine("o.",p)
Line 148 ⟶ 176:
o.myMethod1[1]
o.myMethod2[2]
o.#cast[1]
</pre>
 
Line 378 ⟶ 405:
Sub func(image.Point, image.Point) image.Point func(image.Point) image.Point
</pre>
 
=={{Header|Insitux}}==
 
Insitux does not have classes and therefore technically does not have methods. However, it is possible to list all the functions in global lexical space:
 
<syntaxhighlight lang="insitux">
; lists all built-in and user-defined functions, including those within variables
(-> (symbols)
(map eval)
(filter (comp type-of (= "func"))))
 
; lists only user-defined functions, including those within variables
(-> (symbols)
(map eval)
(filter (comp type-of (= "func")))
(remove about))
</syntaxhighlight>
 
=={{header|J}}==
Line 1,355 ⟶ 1,399:
 
Note that, since attributes are stored internally as a map, the order in which the method names appear is undefined.
<syntaxhighlight lang="ecmascriptwren">#! instance_methods(m, n, o)
#! instance_properties(p, q, r)
class C {
162

edits