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

Re: [Xotcl] proper way to access xotcl classes

From: Gustaf Neumann <neumann_at_wu-wien.ac.at>
Date: Thu, 08 May 2008 18:19:09 +0200

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"