title: difference between uninitialized and initialized class variable in itcl
body: <p>I have used the following two versions of a class variable:</p>
  
  <pre><code>::itcl::class Subcase {
      variable _id
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>::itcl::class Subcase {
      variable _id    -1
  }
  </code></pre>
  
  <p>Obviously, the only apparent difference, is that the former does not have an initial value.
  When I use my Accessor, which is defined as:</p>
  
  <pre><code>public method ::hwascii::Subcase::Id {{newValue __keep__}} { if {$newValue != "__keep__"} { set _id $newValue }; return [set _id] }
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>can't read "_id": no such variable
  </code></pre>
  
  <p>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.</p>
  
  <p>Note1: Setting the value through my accessor always works. </p>
  
  <pre><code>s info variable _id
  </code></pre>
  
  <p>will report either</p>
  
  <pre><code>protected variable ::hwascii::Subcase::_id -1 42
  </code></pre>
  
  <p>or </p>
  
  <pre><code>protected variable ::hwascii::Subcase::_id &lt;undefined&gt; 42
  </code></pre>
  
  <p>depending on whether I have the initialized version or not.</p>
  
  <p>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.</p>
  
  <p>Note3: 
  My Version of tcl is 8.5
  My Version of itcl is 3.4
  both cannot be changed</p>
  
  <p>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:     </p>
  
  <pre><code>http://www.tcl.tk/man/tcl8.6/Itcl4.0.0Cmd/class.htm#M22
  </code></pre>
  
  <p>or even more general will not do.</p>