I have used the following two versions of a class variable:
::itcl::class Subcase {
variable _id
}
and
::itcl::class Subcase {
variable _id -1
}
Obviously, the only apparent difference, is that the former does not have an initial value. When I use my Accessor, which is defined as:
public method ::hwascii::Subcase::Id {{newValue __keep__}} { if {$newValue != "__keep__"} { set _id $newValue }; return [set _id] }
to first set and then get back that value, I will get two different behaviours, depending on which version above I have used to declare the variable. In the first uninitialized case, the accessor will always throw:
can't read "_id": no such variable
but with the second declaration, it will work as expected and return either the initial value, or if it has been changed, that new value.
Note1: Setting the value through my accessor always works.
s info variable _id
will report either
protected variable ::hwascii::Subcase::_id -1 42
or
protected variable ::hwascii::Subcase::_id <undefined> 42
depending on whether I have the initialized version or not.
Note2: The accessor is a one liner, because it is generated in a proc, which uses concat and uplevel to generate a kind of "default" accessor.
Note3: My Version of tcl is 8.5 My Version of itcl is 3.4 both cannot be changed
Question: I have a working solution now, but would like to understand what the difference is. A good explanation will answer my question, a pointer to a good documentation would also be nice, but obvisously a link to:
http://www.tcl.tk/man/tcl8.6/Itcl4.0.0Cmd/class.htm#M22
or even more general will not do.