Reflection/List methods: Difference between revisions

Added Wren
m (→‎{{header|Phix}}: added syntax colouring the hard way)
(Added Wren)
Line 1,200:
 
For <i>many</i> more examples, see https://wiki.tcl.tk/40640 and the linked manuals for <tt>info class</tt> and <tt>info object</tt>. Plugins for <b>tkcon</b> and <b>twDebugInspector</b> (also found on the wiki) use this to create interactive object inspectors similar to [[Smalltalk]]'s.
 
=={{header|Wren}}==
Wren doesn't currently have reflection as such but it's possible to identify a class's methods and list them at runtime by placing a suitable attribute on the class.
 
Note that, since attributes are stored internally as a map, the order in which the method names appear is undefined.
<lang ecmascript>#! instance_methods(m, n, o)
#! instance_properties(p, q, r)
class C {
construct new() {}
 
m() {}
 
n() {}
 
o() {}
 
p {}
 
q {}
r {}
}
 
var c = C.new() // create an object of type C
System.print("List of instance methods available for object 'c':")
for (method in c.type.attributes.self["instance_methods"]) System.print(method.key)</lang>
 
{{out}}
<pre>
List of instance methods available for object 'c':
n
m
o
</pre>
 
=={{header|zkl}}==
9,476

edits