View · Search · Index
No registered users in community xowiki
in last 10 minutes

[Xotcl] proper way to access xotcl classes

From: Matthew Smith <chedderslam_at_gmail.com>
Date: Wed, 7 May 2008 12:54:20 -0500

I am trying to learn xotcl classes and their use from the xotcl-
core.pdf examples. Most of the code examples look like they are being
entered into a console while I am trying to write tcl files and then
run them.

Here's the class definition:
------------------------------------------------------------
package require XOTcl
::xotcl::Class Stack
Stack instproc init {} {
# Constructor
my instvar things
set things ""
}

Stack instproc push {thing} {
my instvar things
set things [concat [list $thing] $things]
return $thing
}

Stack instproc pop {} {
my instvar things
set top [lindex $things 0]
set things [lrange $things 1 end]
return $top
}

---------------------------------------------------------
How do I access the class methods(i guess they are called) from within
the tcl file?
The examples show this:
--------------------------------------------------------
# Create Object s1 of class Stack
% Stack s1
::s1
% s1 push a
a
% s1 push b
b
% s1 push c
c
% s1 pop
c
% s1 pop
b
# Delete object s1
s1 destroy
--------------------------------------------------------

I have tried this:
set s1 [Stack]
puts $s1

Which outputs:
::Stack

But I'm not sure where to go from here...
Thank you.