Skip to content

Instantly share code, notes, and snippets.

@mrcalvin
Created February 16, 2021 11:19
Show Gist options
  • Select an option

  • Save mrcalvin/ccb7197081f2b8fa4be328d86b0c00f6 to your computer and use it in GitHub Desktop.

Select an option

Save mrcalvin/ccb7197081f2b8fa4be328d86b0c00f6 to your computer and use it in GitHub Desktop.
# https://stackoverflow.com/questions/66201923/upvar-tcloo-and-next-explanation-of-perhaps-unexpected-behaviour
oo::class create C1 {
variable aDict
method addone {} {
dict incr aDict xx
}
method getADict {} {
return $aDict
}
}
oo::class create S1 {
superclass C1
method addone {} {
my variable aDict
next;
dict incr aDict xx;
}
}
oo::class create S2 {
superclass C1;
method addone {} {
my variable aDict
next
dict incr aDict xx 2;
}
}
set s1 [S1 new];
set s2 [S2 new];
$s1 addone;
puts [$s1 getADict];
$s2 addone;
puts [$s2 getADict];
# Local variables:
# mode: tcl
# tcl-indent-level: 2
# indent-tabs-mode: nil
# End:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment