Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,27 @@
|
|||
% package require TclOO
|
||||
% oo::class create summation {
|
||||
constructor {} {
|
||||
variable v 0
|
||||
}
|
||||
method add x {
|
||||
variable v
|
||||
incr v $x
|
||||
}
|
||||
method value {{var v}} {
|
||||
variable $var
|
||||
return [set $var]
|
||||
}
|
||||
destructor {
|
||||
variable v
|
||||
puts "Ended with value $v"
|
||||
}
|
||||
}
|
||||
::summation
|
||||
% set s [summation new]
|
||||
% # Do the monkey patch!
|
||||
% set [info object namespace $s]::time now
|
||||
now
|
||||
% # Prove it's really part of the object...
|
||||
% $s value time
|
||||
now
|
||||
%
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
% oo::class create summation {
|
||||
constructor {} {
|
||||
variable v 0
|
||||
}
|
||||
method add x {
|
||||
variable v
|
||||
incr v $x
|
||||
}
|
||||
method value {{var v}} {
|
||||
variable $var
|
||||
return [set $var]
|
||||
}
|
||||
destructor {
|
||||
variable v
|
||||
puts "Ended with value $v"
|
||||
}
|
||||
}
|
||||
::summation
|
||||
% set s [summation new]
|
||||
% set s2 [summation new]
|
||||
% oo::objdefine $s export varname
|
||||
% # Do the monkey patch...
|
||||
% set [$s varname time] "now"
|
||||
% $s value time
|
||||
now
|
||||
% # Show that it is only in one object...
|
||||
% $s2 value time
|
||||
can't read "time": no such variable
|
||||
Loading…
Add table
Add a link
Reference in a new issue