Wize /
Declare
Search:  

Declare

The [declare] declaration provides a way to associate a type with a variable. ie.

  declare i int
  declare j Int 99

An important use of declare is when used with the type Array in a namespace (ie. outside of a proc). This instructs weld to ensure that all elements of the array are to be initialized before being used inside of a proc. eg.

  namespace eval ::x {
     variable Array
     declare pc Array
     array set pc {   a 1   b 2 }

     proc foo {} {
        variable pc
         set pc(c) 1;   # Generates a write warning as "c" was not initialized above
         set i $pc(c);  # Also generates a read warning for "c".
     }
  }

Note that Wize implictly assumes a declare for _.

© 2008 Peter MacDonald

Page last modified on June 04, 2009, at 08:22 AM