[Xotcl] proper way to access xotcl classes
Gustaf Neumann
neumann at wu-wien.ac.at
Thu May 8 18:19:09 CEST 2008
Matthew Smith schrieb:
> I copy and pasted what you posted, and still get the error:
> invalid command name "s1"
sorry, my mistake. i did too much cur&paste from your
earlier scripts. The version below should work
-gustaf neumann
===============================
package require XOTcl; namespace import ::xotcl::*
Class Stack
Stack instproc init {} {
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
}
# using unnamed object
set s1 [Stack new]
$s1 push a
$s1 push b
set x [$s1 pop]
puts "The popped value is $x"
# using named object
Stack s1
s1 push c
s1 push d
set x [s1 pop]
puts "The popped value is $x"
More information about the Xotcl
mailing list