[Xotcl] renaming a instproc
Gustaf Neumann
neumann at wu-wien.ac.at
Tue Aug 17 08:28:43 CEST 2010
On 16.08.10 15:36, Kevin Van Workum wrote:
> How do I rename a Class instproc? For example:
>
> Class T -parameter { {msg "Hello world!"} }
> T instproc hi {} {
> puts [my msg]
> }
> T instparametercmd msg
>
> T t
> t hi
>
> t msg "Good Bye!"
> t rename hi bye
> t bye
there is no "rename" method predefined in xotcl.
i would recommend to implement rename in terms of
introspection (see below). with that, your example
works.
> Also, what's the difference between using "instparametercmd" and
> "parametercmd" in the example above?
The difference between "instparametercmd" and "parametercmd"
is the same as the difference between "instproc" and "proc".
The versions starting with "inst" are defined on the class level
and represent methods for instances of the class. Without
"inst", they are methods on objects (object specific methods).
In your example, you do not need "instparametercmd" (which
defines a c-implemented setter method), since the implementation
of the method "parameter" defines it already.
-gustaf neumann
============================================
Object instproc method-serialize {o m prefix name} {
set arglist [list]
foreach v [$o info ${prefix}args $m] {
if {[$o info ${prefix}default $m $v x]} {
lappend arglist [list $v $x] } {lappend arglist $v}
}
lappend r $o ${prefix}proc $name \
[concat [$o info ${prefix}nonposargs $m] $arglist] \
[$o info ${prefix}body $m]
foreach p {pre post} {
if {[$o info ${prefix}$p $m] ne ""} {
lappend r [$o info ${prefix}$p $m]
}
}
return $r
}
Object instproc rename {from to} {
foreach {obj methtype name} [my procsearch $from] break
switch $methtype {
instproc {set newMethod [my method-serialize $obj
$from inst $to]}
proc {set newMethod [my method-serialize $obj $from
"" $to]}
default {error "can't rename [my procsearch $from]"}
}
$obj $methtype $from "" ""
eval $newMethod
}
More information about the Xotcl
mailing list