On 08/04/2019 20:10, Arjen Markus wrote:
> What I do not understand is why the method PlainNext does not exist.
The method exists in the definition scope of the class, but not in the
definition scope of the instance. (These are different, and are stitched
together to form the collection of methods you can call by TclOO's
dispatch engine. That's got lots of caching and cunningness under the
covers to avoid copying stuff where it doesn't need to.) The
[renamemethod] definition command only moves a method around within its
definition scope.
I think you'd have been better off using a forward:
method Setup {dimension} {
if { [string is integer $dimension] } {
::oo::objdefine [self] {
forward next my PlainNext
# I've put extra spaces in above for clarity
}
} else {
TODO
}
}
Alternatively, define “profiles” of how things can work as classes and
mix them in:
method Setup {dimension} {
if { [string is integer $dimension] } {
::oo::objdefine [self] {
mixin PlainPointsProfile
}
} else {
TODO
}
}
...
class PlainPointsProfile {
# next --
# Generate the next point - for a hyperblock
#
method next {} {
return {1 2}
}
}
The best choice depends on whether you're doing a little patching in the
Setup method or bringing in a whole bunch of methods at once. (Also, I
could probably name things better.)
Donal.
--
Donal Fellows — Tcl user, Tcl maintainer, TIP editor.