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 Weld implictly assumes a declare for _.
© 2008 Peter MacDonald