<font class="fixed_width" face="Courier, Monospaced">I am trying to learn xotcl classes and their use from the xotcl- <br> core.pdf examples. Most of the code examples look like they are being <br> entered into a console while I am trying to write tcl files and then <br>
run them. <br> </font><p><font class="fixed_width" face="Courier, Monospaced">Here's the class definition: <br> ------------------------------------------------------------ <br> package require XOTcl <br> ::xotcl::Class Stack <br>
Stack instproc init {} { <br> # Constructor <br> my instvar things <br> set things "" <br> </font></p><div id="qhide_271750" style="display: block;" class="qt"><font class="fixed_width" face="Courier, Monospaced">} <br>
<br></font></div><font class="fixed_width" face="Courier, Monospaced">Stack instproc push {thing} { <br> my instvar things <br> set things [concat [list $thing] $things] <br> return $thing <br> </font><div id="qhide_271751" style="display: block;" class="qt">
<font class="fixed_width" face="Courier, Monospaced">} <br> <br></font></div><font class="fixed_width" face="Courier, Monospaced">Stack instproc pop {} { <br> my instvar things <br> set top [lindex $things 0] <br> set things [lrange $things 1 end] <br>
return $top <br> </font><div id="qhide_271752" style="display: block;" class="qt"><font class="fixed_width" face="Courier, Monospaced">} <br> <br></font></div><font class="fixed_width" face="Courier, Monospaced">--------------------------------------------------------- <br>
How do I access the class methods(i guess they are called) from within <br> the tcl file? <br> The examples show this: <br> -------------------------------------------------------- <br> # Create Object s1 of class Stack <br>
% Stack s1 <br> ::s1 <br> % s1 push a <br> a <br> % s1 push b <br> b <br> % s1 push c <br> c <br> % s1 pop <br> c <br> % s1 pop <br> b <br> # Delete object s1 <br> s1 destroy <br> -------------------------------------------------------- <br>
</font><p><font class="fixed_width" face="Courier, Monospaced">I have tried this: <br> set s1 [Stack] <br> puts $s1 <br> </font></p><p><font class="fixed_width" face="Courier, Monospaced">Which outputs: <br> ::Stack <br>
</font></p><p><font class="fixed_width" face="Courier, Monospaced">But I'm not sure where to go from here... <br> </font></p><font class="fixed_width" face="Courier, Monospaced">Thank you. </font>