Reflection/List properties: Difference between revisions

added Tcl
(added Tcl)
Line 420:
p Foo.class_variable_set(:@@abc, 123) #=> 123
p Foo.class_variables #=> [:@@xyz, :@@abc]</lang>
 
=={{header|Tcl}}==
Tcl objects do not have properties exactly (externally visible variables), though a common idiom pioneered by <b>Tk</b> is <i>options</i> exposed by the <tt>configure</tt> and <tt>cget</tt> commands.
 
For objects supporting this protocol, you can list all options by invoking the <tt>configure</tt> method without arguments (result split over multiple lines for readability):
 
<lang Tcl>% package require Tk
8.6.5
% . configure
{-bd -borderwidth} {-borderwidth borderWidth BorderWidth 0 0} {-class class Class Toplevel Tclsh}
{-menu menu Menu {} {}} {-relief relief Relief flat flat} {-screen screen Screen {} {}} {-use use Use {} {}}
{-background background Background #d9d9d9 #d9d9d9} {-bg -background} {-colormap colormap Colormap {} {}}
{-container container Container 0 0} {-cursor cursor Cursor {} {}} {-height height Height 0 0}
{-highlightbackground highlightBackground HighlightBackground #d9d9d9 #d9d9d9}
{-highlightcolor highlightColor HighlightColor #000000 #000000}
{-highlightthickness highlightThickness HighlightThickness 0 0} {-padx padX Pad 0 0} {-pady padY Pad 0 0}
{-takefocus takeFocus TakeFocus 0 0} {-visual visual Visual {} {}} {-width width Width 0 0}</lang>
 
Two-element sublists (eg <tt>-bd -borderwidth</tt>) represent aliases, and five-element sublists are of the form <tt>{optionName dbName dbClass defaultValue currentValue}</tt>. <tt>dbName</tt> and <tt>dbClass</tt> are related to how the option is specified in the <i>option database</i>.
 
Simply listing the option names is like this:
 
<lang Tcl>% lmap o [. configure] {if {[llength $o] == 2} continue else {lindex $o 0}}
-borderwidth -class -menu -relief -screen -use -background -colormap -container -cursor -height
-highlightbackground -highlightcolor -highlightthickness -padx -pady -takefocus -visual -width
</lang>
 
=={{header|zkl}}==
Anonymous user